По какой-то причине, когда я запускаю тест, Жасмин говорит мне, что "DataFactory" не определен. Любые идеи почему?
describe('Practice', function(){
beforeEach(module('MyApp'));
var ctrl;
beforeEach(inject(function($controller, DataFactory){
spyOn(DataFactory, 'getArtists').andCallThrough();
ctrl = $controller('ArtistCtrl')
}));
it('should have array available on load', function(){
expect(DataFactory.getArtists).toHaveBeenCalled();
expect(DataFactory.getArtists.callCount).toEqual(1);
});
});
angular.module('MyApp')
.factory('DataFactory', ['$http', function($http){
return {
getArtists: function(){
return $http.get('artists.json');
}
}
}]);
Вы должны определить DataFactory в своем тесте.
Сделай это.
describe('Practice', function(){
var ctrl;
var DataFactory;
beforeEach(module('MyApp'));
beforeEach(inject(function($controller, _DataFactory_){
DataFactory = _DataFactory_;
spyOn(DataFactory, 'getArtists').andCallThrough();
ctrl = $controller('ArtistCtrl', {
DataFactory: DataFactory
});
}));
it('should have array available on load', function(){
expect(DataFactory.getArtists).toHaveBeenCalled();
expect(DataFactory.getArtists.callCount).toEqual(1);
});
Для поддержки вам нужно показать код, в котором вы определяете DataFactory!
Здесь я вижу еще одну опечатку:
expect(DataFactory.getArtists).toHaveBeenCalled();
expect(dataFactory.getArtists.callCount).toEqual(1); <-- DataFactory instead of dataFactory