Home > Blockchain >  TestCafe: await t.expect(Selector().exists).ok() sporadically throwing a TypeError
TestCafe: await t.expect(Selector().exists).ok() sporadically throwing a TypeError

Time:03-09

Is there any possible reason for await t.expect(Selector().exists).ok() to throw TypeError: Cannot read property '0' of null? It happens sporadically so it's hard to track down but my understanding is that if the Selector is not present in the DOM tree then it should wait the timeout and throw an expected boolean to be boolean if not found error. I know I'm not providing much to go on but I'm unable to reproduce the issue on a production facing website. Any help would be greatly appreciated.

Edit: This is on version 1.18.3 of TestCafe but I'm uncertain if it happens in other versions as well.

CodePudding user response:

It's hard to find the cause of the issue without a test code example. Could you please insert the t.wait method with a big timeout before each potential problematic place, e.g.

await t.expect(Selector().exists).ok() ?

Then, observe how the tests are passed to see if the issue depends on the timeout.

Please pay attention to the following information from Selector Timeout:

Selector timeouts have no effect on Selector.exists and Selector.count properties. These properties are evaluated immediately regardless of a timeout. To apply a timeout to exists and count assertions, pass the timeout to the assertion method (expect.ok, expect.eql, etc.). If the issue depends on the timeout, please share a small test code snippet where the problem is reproduced.

If the problem is reproduced independently from the timeout, this means that the issue is in another part of your code.

CodePudding user response:

While I didn't discover the root cause of the failure, wrapping the expect methods in a retry has completely eliminated the error. I'll update this topic if I get any additional information around the original issue.

  • Related