UNPKG

@shopify/jest-dom-mocks

Version:
31 lines (27 loc) 785 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); class Location { mock() { if (this.locationSpy) { throw new Error('You tried to mock window.location when it was already mocked.'); } this.locationSpy = jest.spyOn(window, 'location', 'get'); this.locationSpy.mockReturnValue({ ...window.location, assign: jest.fn((..._args) => {}), reload: jest.fn(() => {}), replace: jest.fn((..._args) => {}) }); } restore() { if (!this.locationSpy) { throw new Error('You tried to restore window.location when it was already restored.'); } this.locationSpy.mockRestore(); this.locationSpy = null; } isMocked() { return Boolean(this.locationSpy); } } exports["default"] = Location;