In my testcafe test, I have a selector that matches multiple nodes. I want to execute an assertion on all nodes that are matched by this selector.
This will perform the assertion only on the first element returned by mySelector
await t.expect(mySelector.innerText).eql("foo");
This will perform it on all elements, but it is really verbose:
const count= await mySelector.count;
for (let i = 0; i < count; ++i) {
await t.expect(mySelector.nth(i).innerText).eql("foo");
}
Is there a built-in way to do this that I am missing?
TestCafe doesn't have methods like
expectEach
so I think the way you propose is the best one. It adds a few lines of code but it makes it clear what you want to check in your test.