function isWindowAvailable() {
return typeof window !== 'undefined';
}
jest test
it('should return false if window is not available', () => {
const windowClone = Object.assign({}, window);
// @ts-ignore
window = undefined;
expect(isWindowAvailable()).toBe(false);
window = windowClone;
});
I want to test the function isWindowAvailable() using jest by deleting or somehow mocking window object to undefined. deleting delete window did not work. What is the correct way to achieve this?