I have strange occurence when testing my hybrid application build with cordova and ionic.
I use karma-jasmine for the unit-testing. If I run my test files sparately they succeed. If I run 3 of them together, they still succeed. If include all of them in karma (path/tests/*.js) 3 out of 5 succeed and following error occurs: "StatusBar" is not defined.
StatusBar is the cordova plugsin "cordova-plugin-statusbar". I wonder why it only appears when testing all files together and not one by one. I already tried to reorder the testfiles, but they always failed after the third testfile.
Everytime a test is fired, the app.js is initialized and started. I don't know if this may be a problem.
Any suggestions?
The problem was, I did not mock my angular application module. In the run function of my module I got the $ionicPlatform to listen for the "deviceReady" event. In this event I access cordova plugins like Statusbar and others. But since I did not mock the application module with its plugins, the tests started failing as soon as the deviceready event was triggered.
To solve the issue I just defined a global variable "testEnvironment" and since I don't want to test my run method in the module, I just check if testEnvironment is true and exit the run method. I defined the variable globally and set it as soon as I start my unit-tests.
I hope someone with a similar issue finds this helpful.