Angular karma phantom before each hook error

I run my tests with karma and phantom, I use mocha and sine, and sometimes the tests pass, and sometimes for no reason I get these errors:

✖ "before each" hook: workFn ✔ should call get user api ✖ "after each" hook for "should call get user api" Finished in 1.04 secs / 0.2 secs SUMMARY: ✔ 42 tests completed ✖ 3 tests failed FAILED TESTS: UserService ✖ "before each" hook: workFn PhantomJS 1.9.8 (Mac OS X 0.0.0) TypeError: 'null' is not an object (evaluating 'document.querySelector('.arrow' + index).classList') (public/client/build/main.js:3195) ✖ "after each" hook for "should call get user api" PhantomJS 1.9.8 (Mac OS X 0.0.0) PhantomJS 1.9.8 (Mac OS X 0.0.0) TypeError: 'null' is not an object (evaluating 'currentSpec.$injector') at public/vendor/angular-mocks/angular-mocks.js:2229 

What can cause this problem?

+8
javascript angularjs karma-mocha
source share
2 answers

In my experience, calling the DOM using Karma and / or PhantomJS can be a problem. The PhantomJS DOM does not work exactly like a standard browser, and as such, it often causes an error when working with the GUI.

My advice (though this may not be the best) is to track or mock the document methods that you use with document , since what they do doesn't work anyway.

+3
source share

the problem is clearly isolated from the output of karma, isn't it?

'document.querySelector('.arrow' + index).classList'

it could not find the element by selector, so the classList from undefined is null. You need to study it.

0
source share

All Articles