1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var Location = (function () {
|
4 | function Location() {
|
5 | this.isUsingMockLocation = false;
|
6 | }
|
7 | Location.prototype.mock = function () {
|
8 | if (this.isUsingMockLocation) {
|
9 | throw new Error('You tried to mock window.location when it was already mocked.');
|
10 | }
|
11 |
|
12 |
|
13 | Reflect.defineProperty(window.location, 'search', {
|
14 | writable: true,
|
15 | value: '',
|
16 | });
|
17 | this.assignSpy = jest.spyOn(window.location, 'assign');
|
18 | this.reloadSpy = jest.spyOn(window.location, 'reload');
|
19 | this.replaceSpy = jest.spyOn(window.location, 'replace');
|
20 | this.isUsingMockLocation = true;
|
21 | };
|
22 | Location.prototype.restore = function () {
|
23 | if (!this.isUsingMockLocation) {
|
24 | throw new Error('You tried to restore window.location when it was already restored.');
|
25 | }
|
26 | location.search = '';
|
27 | this.assignSpy.mockRestore();
|
28 | this.reloadSpy.mockRestore();
|
29 | this.replaceSpy.mockRestore();
|
30 | this.isUsingMockLocation = false;
|
31 | };
|
32 | Location.prototype.isMocked = function () {
|
33 | return this.isUsingMockLocation;
|
34 | };
|
35 | return Location;
|
36 | }());
|
37 | exports.default = Location;
|