Some of your tests did a full page reload - error when running Jasmine tests

31,190

Solution 1

In my case the problem was that in my source code I had code directly setting the href on the location object, like window.location.href = 'somewhere';

In my specs I set up a onbeforeunload listener that just returns a string instead of allowing the redirect to take place:

beforeAll(() => {
  window.onbeforeunload = () => 'Oh no!';
});

Solution 2

I suppose you are using window.location somewhere in your targeted code. In order to pass it just create a spy for the window.onbeforeunload

Example:

window.onbeforeunload = jasmine.createSpy();

Or even better use $window instead, and this will not happen.

Solution 3

Make sure that your tests are properly isolating all modules under test with mocks/spies. The behavior you are seeing says to me that your tests are not truly running in isolation - they are changing some state somewhere that will trigger a reload.

Solution 4

I recently encountered this error with Karma 0.13.12. I upgraded to Karma 0.13.14 and my tests work again. The problem for me (and probably also for @mqklin) was related to https://github.com/karma-runner/karma/issues/1656 and https://github.com/jasmine/jasmine/issues/945.

Solution 5

What worked for me was upgrading Karma from 1.4.0 to 1.4.1 and changing the maximumSpecCallbackDepth in my jasmine.js file from 20 to 100.

Share:
31,190
Siraris
Author by

Siraris

Updated on July 10, 2022

Comments

  • Siraris
    Siraris almost 2 years

    I'm running into an issue where when I run my tests on Jasmine, I get this error below. The problem is, it seems to happen when I try to execute a certain amount of tests. It doesn't seem to be tied to a particular test, as if I comment out some, the tests pass. If I uncomment some tests, the error appears. If I comment out ones that were uncommented before, they all pass again. (ie if I have red, green, blue and orange test and it fails, I comment out orange and blue it passes, then I uncomment blue and orange it fails again, but if I comment out red and green it passes again).

    Chrome 41.0.2272 (Mac OS X 10.10.1) ERROR Some of your tests did a full page reload! Chrome 41.0.2272 (Mac OS X 10.10.1): Executed 16 of 29 (1 FAILED) ERROR (0.108 secs / 0.092 secs)

    I'm stumped as to what is going on. The more tests I add, that's when this becomes an issue. Has anyone encountered this before? I have no idea what could be causing it, as nothing in any of my tests do any kind of redirection, and they all pass universally on another persons machine.

  • Christian Dalager
    Christian Dalager about 9 years
    I actually found the place after offering the bounty. And yes, you are right on the money. In my case the reload was triggered after a certain amount of tests for some reason - because of a pending http-httprequest to an external system that timed out exactly between test 13 and 14... ;)
  • Admin
    Admin over 7 years
    Please reformat this answer and expand it a little bit.
  • Dov Benyomin Sohacheski
    Dov Benyomin Sohacheski almost 7 years
    Can you be more specific?
  • Easwaramoorthy K
    Easwaramoorthy K almost 7 years
    It worked, but with an argument inside createSpy - just a string.
  • ada
    ada almost 6 years
    seems as nice suggestion but I got 'assign is not declared writable or has no setter'
  • Roy.L.T
    Roy.L.T about 2 years
    Thank you very much! This answer just saved my day! Turns out the buttons within <form> element are specified to type="submit" (by default). After changing them to type="button", it solves the problem.