javascript - Testcafe过滤功能
问题描述
我有一个 Selector 的过滤器函数,如下所示,它接受两个参数
{ subject: subject, from: from }
作为依赖项对象。
但是运行这个函数后,我得到一个错误
ReferenceError:未定义主题
async function getMessage(subject, from) {
return await Selector('[data-test=messageListItem]').filter(( message ) => {
return message.querySelector('[data-test=subject]').textContent.includes(subject) &&
message.querySelector('[data-test=email]').textContent.includes(from);
}, { dependencies: { subject: subject, from: from } });
}
TestCafe 团队可以帮我解决这个问题吗?
解决方案
在.filter
方法的情况下,您需要重写您的依赖项参数 ( { dependencies: { subject: subject, from: from } }
),如下所示:
{ subject: subject, from: from }
我准备了一个示例测试来说明它:
import { Selector } from 'testcafe';
fixture `New Fixture`
.page `google.com`;
test('New Test', async t => {
await t
.click(Selector('#tsf').find('[name="q"]'))
.typeText(Selector('#tsf').find('[name="q"]'), 'testcafe')
.pressKey('enter');
await t.expect(Selector('.LC20lb').count).eql(10);
function fn (title) {
return Selector('.LC20lb').filter((node, idx) => {
return node.textContent.includes(title);
}, { title }); // dependencies parameter
}
await t.expect(fn('TestCafe').count).gt(1);
});
推荐阅读
- python - 如何通过python终止shell程序
- promise - 法罗承诺:
- arcore - 使用 arcore 更改场景形式中表面的图像搜索
- regex - 提取shell中get参数的值
- string - 如何根据文本文件修改日期搜索关键字?
- angular - Atlasian Elastic Bamboo 构建错误:Angular CLI 构建的打开文件过多错误
- php - PHP json编码到JS没有得到完整的HTML
- c++ - 使用 CMake 构建可移植 Python C-API
- android - 找不到 Firestore Android 的 whereArrayContains() 方法
- system-verilog - 将字段从一个类复制到序列项中的另一个