jeudi 19 mai 2016

Minified $provider injection with jasmine and angular

We have a project (angular) and some unittests for it (jasmine+sinon), which when minified creates some issues. For the actual code, we've solved these problems by injecting using the staticly typed string array, e.g. ['locationService', 'etcService']. Unfortunately for the unittests, the minification has some more problems to solve. As an example:

module(function($provide){
    $provide.service('etc..',...);
}

Code above immediately becomes unusuable since the provider variable gets renamed to something like 'a'. I've tried to tweak it a bit wrapping the function with something like below:

function injectTest($provide){
    // do the same stuff
}
injectTest.$inject = ['$provide'];

which was a recommended solution in some other online posts. The problem is with modules this really doesn't work. I've tried both:

module(angular.injector().invoke(injectTest)); // which results in 'Unknown provider: $provideProvider <- $provide

and

module(injectTest); // which results in 'Unknown provider: nProvider <- n'

Is there any way to inject the $provider into a module without breaking on minification?

Aucun commentaire:

Enregistrer un commentaire