How Can I Set Window To Undefined In Order To Test The Ssr Rendering In An Isomorphic Application?
I have been trying to test an else block for when window is undefined. As I'm using Next.js the window will be undefined during server side rendering (SSR). At present I can not fi
Solution 1:
/**
* @jest-environment node
*/import getLanguage from'./getLanguage';
describe('Get Language SSR', () => {
it('should return "en"', () => {
expect(getLanguage()).toEqual('en'); // SUCCESS
})
});
The @jest-environment
docblock will set the test environment for this test file to node
causing window
to be undefined
and resulting in the test passing.
Post a Comment for "How Can I Set Window To Undefined In Order To Test The Ssr Rendering In An Isomorphic Application?"