For my Integration tests, I need to mock the browser date and to accomplish that I'm using clientScripts injecting the mockdate module:
const clientScriptsObject = [
{ module: 'mockdate' },
{ content: "MockDate.set('2020-04-19')" },
];
For this issue, I created a small project that goes to Wikipedia and tries to search for something but using an incorrect selector:
const mockDate = `
Date.now = function () {
return 1566408247;
};
`;
fixture('My first fixture').page('https://www.wikipedia.org/');
test('users can search', async (t) => {
await t
.click(Selector('#searchInput'))
.click(Selector('#this-selector-does-not-exist'))
.typeText(Selector('#searchInput'), 'vikings')
.click(Selector('button[type=submit]'));
}).clientScripts({ content: mockDate });
```
### What is the Current behavior?
<!-- Describe the behavior you see and consider invalid. -->
When the tests execute ` .click(Selector('#this-selector-does-not-exist'))` the `Selector` get stuck waiting for the element to appear, ignoring the default (and setted) selector timeouts:

### What is the Expected behavior?
<!-- Describe what you expected to happen. -->
To raise an error specifying that the selector does not exist.

### What is聽your web application and聽your TestCafe聽test code?
<!-- Share a public accessible link to your application or provide a simple app which we can run. -->
You can access the code here:
https://github.com/Thormod/testcafe-issue
<details>
<summary>Your website URL (or attach your complete example):</summary>
<!-- Provide your website URL or attach a sample. Note: if your website requires any additional access procedures like authentication, please ask the website owner to send us a written confirmation at [[email protected]](mailto:[email protected]) in a free text form. It will allow the DevExpress staff to remotely access the website and its internal resources for research, testing, and debugging purposes. -->
</details>
<details>
<summary>Your complete test code (or attach your test files):</summary>
<!-- Paste your test code here: -->
```js
Your complete configuration file (if any):
Your complete test report:
Screenshots:
Just run npm run test on the example project, or mock the Date.now() function by using clientScript
testcafe chromei have a similar issue when i mock date object in test cafe, I guess the testcafe timeouts use the same object we are mocking?
I'm having the same issue when I try to avoid external dependencies with mocks and I'm dealing with dates. I'm interested
I'm also having the same issue with the mock dates. I'm also interested, this also happens on Linux Mint 19.3 Tricia
im having the exact same issue
I'm also having the same issue
I'm also having the same issue! And I see I'm not the only one
Hi @Thormod
Thank you for the detailed information. I've reproduced the problem.
@miherlosev Do you know when the new version will be released? PD: Thank you for solving this bug!
A release candidate version [email protected] is already published to NPM. You can test it in your environment if you do not mind installing preliminary versions. Once we test it and create a changelog, we will publish a stable release.
@AndreyBelym @miherlosev There are some TypeErrors in the new version:

Uncaught TypeError: Cannot read property 'destUrl' of null
at Function.t._sameOriginCheck (worker-hammerhead.js:1)
at r.fetch (worker-hammerhead.js:1)
at u (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
at b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2
at xt (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
at Object.bt [as getArrayBuffer] (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
at l.s [as loadVectorData] (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
at l.loadTile (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
at ke.loadTile (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
at __call$ (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:1)
It seems to be related with the fetch requests:

I cannot reproduce the issue with Wikipedia.org. But I created my own example, which demonstrates a very similar issue: https://github.com/DevExpress/testcafe-hammerhead/issues/2428. The version with the fix is already published to NPM as [email protected]. As my example and the fix is based on assumptions only, there is a risk that it doesn't fix your specific issue. Could you please try to install [email protected] and provide a sample test page if you still can reproduce the issue in your environment?
@AndreyBelym It worked! Thank u for solving this so fast!
Most helpful comment
Hi @Thormod
Thank you for the detailed information. I've reproduced the problem.