✅(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:
@@ -24,13 +24,22 @@ describe('utils', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checks support session is terminated when logout', () => {
|
it('checks support session is terminated when logout', () => {
|
||||||
|
jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
|
||||||
window.$crisp = true;
|
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: {
|
value: {
|
||||||
...window.location,
|
...window.location,
|
||||||
replace: jest.fn(),
|
replace: jest.fn(),
|
||||||
},
|
},
|
||||||
writable: true,
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
gotoLogout();
|
gotoLogout();
|
||||||
|
|||||||
Reference in New Issue
Block a user