Wednesday, 3 March 2021

history.back not behaving as expected in Karma

When I run a basic test case like this:

  fdescribe('Browser back button', () => {

    fit('should return to previous', async () => {

      const originalHref = window.location.href;
      window.history.pushState({}, 'Test', '/test');
      window.history.back();  // This doesn't seem to be working.
      expect(window.location.href).toEqual(originalHref);
    });

I get a failure with the message "Expected 'http://localhost:9876/test' to equal 'http://localhost:9876/context.html'." So clearly the pushState() worked but the back() did not.

Karma runs tests in an inner iframe. When I paste the first three lines in order into the browser's JavaScript console, the navigation works as expected. So there must be something different between the behavior of the window and the behavior of the inner iframe in this case.

This is Karma 5.1 on Chrome.

Any thoughts?



from history.back not behaving as expected in Karma

No comments:

Post a Comment