I have a filter function for Selector as following which accepts two parameters
{ subject: subject, from: from }
as a dependencies object.
But after running this function, I am getting an error
ReferenceError: subject is not defined
JavaScript
x
7
1
async function getMessage(subject, from) {
2
return await Selector('[data-test=messageListItem]').filter(( message ) => {
3
return message.querySelector('[data-test=subject]').textContent.includes(subject) &&
4
message.querySelector('[data-test=email]').textContent.includes(from);
5
}, { dependencies: { subject: subject, from: from } });
6
}
7
Can TestCafe team please help me with this?
Advertisement
Answer
In the case of the .filter
method you need to rewrite your dependencies parameter ({ dependencies: { subject: subject, from: from } }
) as follows:
JavaScript
1
2
1
{ subject: subject, from: from }
2
I have prepared a sample test to illustrate it:
JavaScript
1
23
23
1
import { Selector } from 'testcafe';
2
3
fixture `New Fixture`
4
.page `google.com`;
5
6
test('New Test', async t => {
7
await t
8
.click(Selector('#tsf').find('[name="q"]'))
9
.typeText(Selector('#tsf').find('[name="q"]'), 'testcafe')
10
.pressKey('enter');
11
12
await t.expect(Selector('.LC20lb').count).eql(10);
13
14
15
function fn (title) {
16
return Selector('.LC20lb').filter((node, idx) => {
17
return node.textContent.includes(title);
18
}, { title }); // dependencies parameter
19
}
20
21
await t.expect(fn('TestCafe').count).gt(1);
22
});
23