gpt4 book ai didi

javascript - Testcafe过滤功能

转载 作者:行者123 更新时间:2023-11-28 21:16:21 24 4
gpt4 key购买 nike

我有一个 Selector 的过滤器函数,如下所示,它接受两个参数 { subject: subject, from: from } 作为依赖对象。

但是运行这个函数后,我得到一个错误

ReferenceError: subject is not defined

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 团队可以帮我解决这个问题吗?

最佳答案

In the case of the .filter method你需要重写你的 dependencies 参数 ({ 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);
});

关于javascript - Testcafe过滤功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57627053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com