Running more than 10 tests of karma using jasmine causes: "ERROR: some of your tests did a full page reload!"

So this is my first project in which I use Karma and Jasmine to unit test my angularJS code. The Yeoman angular generator is used for tuning.

As soon as I reached 11 tests, I got an error: "Some of your tests did a full page reload." I do not do any tests that can cause a reboot.

Digging deeper, I saw the exact same issue that Github refers to. https://github.com/jasmine/jasmine/issues/366 - (FuzzySockets comments)

The problem seems to be related to the line of code in the jasmine core https://github.com/jasmine/jasmine/blob/master/lib/jasmine-core/jasmine.js

To avoid, the value of maximumSpecCallbackDepth is 20. And each time currentSpecCallbackDepth exceeds this, additional tests are performed on the new stack using the setTimout function.

This is a line that seems to cause problems and cause karma to throw an error. (I checked this by calling the setTimeout in my own unit test, and it threw the same error).

If I change the maximumSpecCallbackDepth value to 100, my tests run fine and no errors occur at the end.

Has anyone seen this problem and knew about a fix? I use the latest versions of karma (0.13.15) and jasmine (2.4.1).

I haven’t messed up too much with the default grunt or karma setting that appeared with your generated yogis, except that I use chrome launcher instead of the standard phantomJS, so I don’t understand how everyone else doesn’t have a problem here.

+5
source share
2 answers

+1 for this problem. As I said, this is caused by the maximumSpecCallbackDepth restriction, but so far I have not found a fix for this problem. You could probably track the problem here https://github.com/karma-runner/karma/issues/1101 .

One temporary solution is to shorten the “describe” nested block in your project.

+1
source

I had a similar problem when angular injections in global beforeEach stopped working and all tests failed after 20 prefix maximumSpecCallbackDepth.

During my research, I found that angular-mock does not work very well with setTimeout made in jasmine when this limit is reached.

The following code, cited as an example everywhere, will create a new injector in each test case:

 var yourService; beforeEach(module('app')); beforeEach(inject(function(_yourService_) { yourService = _yourService_; })); 

Instead, you can do the following, which will use a single injector and register your modules only once.

 var yourService; module.sharedInjector(); beforeAll(module('app')); beforeEach(inject(function(_yourService_) { yourService = _yourService_; })); 

I hope this would help others, since it took me almost a week to find out that this was the main cause of the problem, and not Jasmine herself, as some people think about github.

+1
source

Source: https://habr.com/ru/post/1237944/


All Articles