UNPKG

@jedmao/location

Version:

A Location class that implements the Location interface of the Web API.

53 lines (52 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Represents the location (URL) of the object it is linked to. * Changes done on it are reflected on the object it relates to. * Both the `Document` and `Window` interface have such a linked `Location`, * accessible via `Document.location` and `Window.location` respectively. */ class LocationMock extends URL { constructor() { super(...arguments); // eslint-disable-next-line @typescript-eslint/no-explicit-any this.ancestorOrigins = []; } /** * Causes the window to load and display the document at the URL specified. */ assign( /** * The URL of the page to navigate to. */ url) { this.href = url; } /** * Reloads the resource from the current URL. * @param forcedReload */ reload( /** * If `true`, the page will always reload from the server. If `false` or * unspecified, the browser may reload the page from its HTTP cache. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars _forcedReload = false) { return; } /** * Replaces the current resource with the one at the provided URL. * The difference from the `assign()` method is that after using `replace()` * the current page will not be saved in session `History`, meaning the user * won't be able to use the back button to navigate to it. */ replace( /** * The URL of the page to navigate to. */ url) { this.href = url; } } exports.LocationMock = LocationMock;