mardi 6 janvier 2015

How can I run common code in tests using Karma + Jasmine + AngularJS?

I'm using Karma to run my unit tests against an AngularJS application. The problem is that I use the ui-router plugin, and the fact that it makes some XHR requests to run the templates forces me to mock those requests. Therefore, I see myself repeating this for every test file:



beforeEach(function($templateCache) {
$templateCache.put('templates/layout.html', '');
$templateCache.put('templates/dashboard/index.html', '');
$templateCache.put('templates/session/login.html', '');
});


How can I run this piece of code for all my unit tests? I tried googling, but no luck. Also, should I be doing this in some other way? Please share your opinions.


Thank you all.


Aucun commentaire:

Enregistrer un commentaire