How to use the jsdom.changeURL function in jsdom

To help you get started, we’ve selected a few jsdom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edrlab / webpub-viewer / test / IFrameNavigatorTests.ts View on Github external
it("should go to next page", async () => {
            jsdom.changeURL(window, "http://example.com");
            const chapterPosition = element.querySelector(".chapter-position") as HTMLSpanElement;
            
            const iframe = element.querySelector("iframe") as HTMLIFrameElement;
            paginatorCurrentPage = 4;

            // If you're not on the last page, it goes to the next page.
            eventHandler.onRightTap(new UIEvent("mouseup"));
            expect(onLastPage.callCount).to.equal(1);
            expect(goToNextPage.callCount).to.equal(1);
            expect(chapterPosition.innerHTML).to.equal("Page 4 of 8");

            await pause();
            expect(saveLastReadingPosition.callCount).to.equal(2);
            expect(saveLastReadingPosition.args[1][0]).to.deep.equal({
                resource: "http://example.com/start.html",
                position: 0.25
github gajus / isomorphic-webpack / src / utilities / evalCodeInBrowser.js View on Github external
export default (code: string, userOptions: RunInNewContextType = {}, windowUrl?: string): any => {
  const window = jsdom.jsdom('').defaultView;

  if (windowUrl) {
    jsdom.changeURL(window, windowUrl);
  }

  const sandbox = {
    console,
    document: window.document,
    ISOMORPHIC_WEBPACK: true,
    process: {
      env: {
        // eslint-disable-next-line no-process-env
        NODE_ENV: process.env.NODE_ENV
      }
    },
    require,
    window
  };
github LINKIWI / linkr / test / frontend / app / util / test-browser.js View on Github external
test('browser.parseURL parses current URL with query string', (t) => {
  jsdom.changeURL(window, 'https://auth.kevinlin.info?redirect=https://google.com');

  const parsed = browser.parseURL();

  t.equal(parsed.host, 'auth.kevinlin.info', 'Host is parsed');
  t.equal(parsed.query.redirect, 'https://google.com', 'Query string redirect is parsed');

  t.end();
});
github LINKIWI / linkr / test / frontend / app / util / test-browser.js View on Github external
test('browser.hash sets the current URL hash', (t) => {
  jsdom.changeURL(window, 'https://google.com');

  browser.hash('hash');

  t.equal(window.location.href, 'https://google.com/#hash', 'Hash value is set on URL');

  t.end();
});
github drstarry / A-Tour-of-Colleberative-Editing / test / client / actions / return-url.js View on Github external
lab.test('it handles clearReturnUrl', (done) => {

    const location = global.window.location.toString();
    const query = global.window.location.search;
    const url = location.replace(query, '');

    Jsdom.changeURL(global.window, url);

    const localStorage = global.window.localStorage;

    global.window.localStorage = {
      removeItem: function () {

        global.window.localStorage = localStorage;

        done();
      }
    };

    ReturnUrlActions.clearReturnUrl();
  });
});
github binary-com / binary-static / src / javascript / app / base / __tests__ / tests_common.js View on Github external
const setURL = (url) => {
    jsdom.changeURL(window, url);
    Url.reset();
    Language.reset();
};
github edrlab / webpub-viewer / test / ServiceWorkerCacherTests.ts View on Github external
beforeEach(() => {
        jsdom.changeURL(window, "https://example.com");
        mockNavigatorAPI();
        store = new MemoryStore();
        element = document.createElement("div");
    });