Good morning
I am trying to test our relatively big angular app with karma (or at least start with some tests). I got it to run with some minor troubles but am wondering now; karma offers a beforeEach function, which is called before every it
code block.
When using angular, I (it seems so) have to call module('app')
every time before executing one test case. Isn't that a total performance blocker? I mean setting up the whole module and therefore the app is a total waste of performance no?
When I place the module('app') call in a beforeAll() function I receive a
Error: [$injector:unpr] Unknown provider: CacheFactoryProvider <- CacheFactory
Did anyone experience that? What am I doing wrong setting the test suite up?
Isn't the idea of beforeAll() to allow costy calls like module('app')
to be only made once?
Below is one of my simple tests, which runs at the state I posted it, so my question is simply about the cost of calling the module multiple times :S
/* jshint -W117, -W030 */
describe('blocks.filter.dateFormatter', function() {
var filter, cacheFactory;
//beforeAll(function() {
// module('app');
//});
// Code above leads to unknown provider error
beforeEach(function() {
module('app');
inject(['$filter', 'CacheFactory',
function($filter, $CacheFactory) {
filter = $filter;
cacheFactory = $CacheFactory;
cacheFactory.destroyAll();
}
]);
});
it('dateFormatter convert yyyy-MM-dd hh:mm:ss to dd.MM.yyyy', function() {
expect(filter('formatDate')('2015-09-28 00:00:00')).toBe('28.09.2015');
});
it('dateFormatter convert yyyy-MM-dd to dd.MM.yyyy', function() {
expect(filter('formatDate')('1960-05-05')).toBe('05.05.1960');
});
});
Yes I know, the problem with the cache is solved ugly but I did lose patience with it :)
Any help would be appreciated, thanks in advance.