I spróbuj przetestować poniższy kod:Testy w angularjs: Błąd referencyjny funkcji injekcji
describe('myService test', function() {
describe('when I call myService.one', function() {
beforeEach(angular.module('TargetMarketServices'));
it('returns 1', inject(function (imagesRepository) {
expect(true).toEqual(true);
}));
});
});
Gdy ten kod jest wykonywany otrzymuję ten błąd:
TypeError: 'undefined' is not a function (evaluating 'this.func.apply(this.spec)')
at http://localhost:8080/testacular.js:76
at http://localhost:8080/context.html:35
ReferenceError: Can't find variable: inject
at /home/peter/Dropbox/AngularJS/set-component/test/sets/sets-ihm.js:6
at /home/peter/Dropbox/AngularJS/set-component/test/sets/sets-ihm.js:8
at /home/peter/Dropbox/AngularJS/set-component/test/sets/sets-ihm.js:10
PhantomJS 1.8: Zrealizowane 1 z 3 (1 FAILED) (pomijany 2) (0,072 s/0,01 s)
Do mojego testu używam Testacular z Jasmine i PhantomJS.
Ale kiedy używam tylko modułu, pojawia się błąd "ReferenceError: Can not find variable: module" – ChriX
Przepraszam, miałem na myśli [kątowe-nasienie] (https://github.com/angular/angular-seed) wcześniej, a nie na kanciastą fonekat. Otrzymujesz ReferenceError, zakładam, ponieważ nie masz [angular-mocks.js] (https://github.com/angular/angular-seed/blob/master/test/lib/angular/ angular-mocks.js) w twoim testowym pliku konfiguracji testowania jednostkowego. –
Problem został rozwiązany, biorąc plik kątowy-mocks.js. – ChriX