mercredi 27 juillet 2016

When testing Angular services with Jasmine, is the inclusion order of scripts causing this unknown provider error

I have an Angular service that is including two other modules: logger and toaster. logger.js is local and I've included it in this plunkr. As for toaster it is a third party library, and within the plunker, index.html is including it as a script tag.

This is my first attempt at testing with Jasmine, and I've trimmed things down to be concise. At first I couldn't get the tests to pass due to an injector error related to the logger module. Finally through trial and error, I noticed that, in index.html, if I loaded logger.js after common.js, the error would go away and the tests would pass.

Now I am trying to pass the toaster module into the common service module, but no matter where I include the reference to toaster.min.js, I get the following error. When I run this locally instead of as a plunkr, I can verify that toaster.min.js is getting loaded; furthermore by looking at its content, I've verified that it defines a toaster module. So I am kind of at a loss as to what else to try in order to get toaster to load properly so I can finish the testing of my common service.

Error: [$injector:unpr] Unknown provider: toasterProvider <- toaster <- common

Aucun commentaire:

Enregistrer un commentaire