Running cypress version 13.9.0, I encountered a RangeError while using cy.reload(). The error points to an Invalid time value at Date.toISOString.
Any suggestions on how to resolve this issue?
waitForUpdate(employeeId, employeeName, employeeEmail) {
const token = JSON.parse(localStorage.getItem('activeToken')).token.token;
// Start a clock to control the timeout
cy.clock(new Date());
const checkStatus = () => {
cy.request({
method: 'GET',
url: Cypress.config().baseUrl + `api/v1/employee/${employeeId}`,
headers: {
Authorization: `Bearer ${token}`,
},
}).then((response) => {
expect(response.status).to.equal(200);
const { name, email } = response.body;
if (name === employeeName && email === employeeEmail) {
// Task found and status is as expected
cy.log("Employees' data updated");
cy.reload();
} else if (new Date().getTime() - startTime < 900000) {
// Retry for a maximum of 15 minutes (900000 milliseconds)
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(15000); // Wait for 15 seconds
checkStatus(); // Retry the request
} else {
// Timeout exceeded, fail the test
cy.log('Employees data is not updated within 15 minutes.');
expect(false).to.equal(true); // Fail the test
}
});
};
const startTime = new Date().getTime();
checkStatus(); // Start checking the status
}
Above code throws the following error:
RangeError: The following error originated from your application code, not from Cypress.
> Invalid time value
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the `uncaught:exception` event.
at Date.toISOString (<anonymous>)
at q.end (main.a1444de99b433347.js:1:216062)
at HTMLDocument.<anonymous> (main.a1444de99b433347.js:1:62383)
at I.invokeTask (polyfills.2ba72d64643256ee.js:1:7246)
at B.runTask (polyfills.2ba72d64643256ee.js:1:2614)
at b.invokeTask [as invoke] (polyfills.2ba72d64643256ee.js:1:8300)
at j (polyfills.2ba72d64643256ee.js:1:20943)
at x (polyfills.2ba72d64643256ee.js:1:21349)
at HTMLDocument.J (polyfills.2ba72d64643256ee.js:1:21513)
I tried different methods like page reload and javascript win.reload, but the error persisted. Manipulating cy.clock also did not solve the problem.
EDIT: Removing cy.clock() fixed the issue, as it seemed to interfere with time-based operations in the application.
Instead of cy.clock(), I am now using const startTime = new Date().getTime() while keeping everything else unchanged.