jeudi 5 février 2015

Ignore module.run when unittesting

So I have a initialization function i give to the module.run function:



function initStuff($rootScope, otherService){
//Do some stuff
$rootScope.$on("event", function(){otherService.doOtherStuff();})

}
initStuff.$inject = ["$rootScope", "otherService"];

app.run(initStuff);


Now this works fine and all when running the app. When testing this i just mock $rootScope and otherService and execute the function.


But I'm having trouble with completely other unit tests. Unit tests that are using the standard beforeEach(module("app"));. When those tests are run my guess is that this app.run(initStuff) has also run and executes. And some of those other tests also mock otherService which cause errors, because they might not be using the doOtherStuff()-function, and then i get an error like "undefined is not a function".


So my question is: Is there some way to shut this run function off so it does not execute my initStuff-function? Since this initialization is not relevant when unit testing other parts of the application.


Or is it the other tests that are a bit wrong in using the actual $rootScope causing this listener to execute?


Aucun commentaire:

Enregistrer un commentaire