Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 511
Siraris Avatar asked Mar 30 '15 17:03

Siraris


2 Answers

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!'; }); 
like image 58
jpunk11 Avatar answered Oct 10 '22 00:10

jpunk11


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.

like image 26
johnmcase Avatar answered Oct 09 '22 22:10

johnmcase