Skip to main content

Window

The @archibald/testing package provides functionality to work with window object.

mockWindowLocation

mockWindowLocation function can be used to mock location object.

import { mockWindowLocation } from '@archibald/testing';

mockWindowLocation(LOCATION);

Example

import { mockWindowLocation } from '@archibald/testing'';

describe('mockWindowLocation', () => {
it('should mock window.location object', () => {
const location: Partial<Location> = {
pathname: 'mocked pathname',
reload: jest.fn()
};

mockWindowLocation(location);

expect(window.location.pathname).toBe('mocked pathname');
window.location.reload();
expect(window.location.reload).toBeCalledTimes(1);
});
});