(jest) fix window.location mock

We upgraded to jest 30.0.3.
This upgrade updated jsdom and jsdom now do not
allows to mock window.location.
See: https://github.com/jsdom/jsdom/issues/3492
This commit fixes this issue.
This commit is contained in:
Anthony LC
2025-06-26 16:49:13 +02:00
parent 9f222bbaa3
commit 9b0676ec15

View File

@@ -24,13 +24,22 @@ describe('utils', () => {
});
it('checks support session is terminated when logout', () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
window.$crisp = true;
Object.defineProperty(window, 'location', {
const propertyDescriptors = Object.getOwnPropertyDescriptors(window);
for (const key in propertyDescriptors) {
propertyDescriptors[key].configurable = true;
}
const clonedWindow = Object.defineProperties({}, propertyDescriptors);
Object.defineProperty(clonedWindow, 'location', {
value: {
...window.location,
replace: jest.fn(),
},
writable: true,
configurable: true,
});
gotoLogout();