içine çözülür. Açısal uygulamasında, UI yönlendiricisi denetleyiciye bir söz verir. Bu denetleyiciyi test etmeye çalışırken, Karma bilinmeyen bir sağlayıcıdan şikayet ediyor. Bu çözüm nesnesini temsil etmek için sınamada sahte bir nesneyi nasıl enjekte edebilirim.Köşeli Yasemin UI yönlendiricisi, değeri
angular.module('myapp')
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab.name', {
...
resolve: {
allTemplates: function(Templates) {
return Templates.all().then(function(templates) {
return templates;
});
}
}
})
})
.controller('QueriesCtrl', function(allTemplates, UserQuery) {
var vm = this;
vm.queries = allTemplates;
vm.goToUrl = function(index, data) {
var processedUrl = UserQuery.process(data, vm.queryTyped[index]);
UserQuery.goToUrl(processedUrl);
};
});
Ben
Unknown provider: allTemplatesProvider <- allTemplates <- QueriesCtrl
Ben casus oluşturma ve enjekte etmeye çalıştım hatayı almak testler çalışırken, ancak bu işe yaramazsa: bir şey gibi
Benim uygulamanın kod görünüyor . Eğer $controller
fonksiyonu ile normal bir nesne olarak allTemplates
enjekte etmek zorunda kalacak birim teste tabi tutulan hiçbir rota olmadığı için
describe('Unit: queriesCtrl', function() {
var controller,
scope,
UserQuery;
beforeEach(function() {
module('myapp');
inject(function($injector) {
UserQuery = $injector.get('UserQuery');
allTemplates = jasmine.createSpyObj('allTemplates', [{a:1}, {a:2}, {b:3}]);
});
});
describe('goToUrl', function() {
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('QueriesCtrl as ctrl', {
'$scope': scope
});
}));
it('should call UserQuery.process()', function() {
spyOn(UserQuery, 'process');
scope.ctrl.goToUrl();
expect(UserQuery.process).toHaveBeenCalled();
});
});
});
@ Chandermani, mocha-Chai'ye yeni geldim, http://stackoverflow.com/questions/28606056/mocha-chai-test-case-for-angular-configuration-file adresinde yayınlanan benzer bir sorunla ilgili olarak lütfen yardımcı olabiliriz – mayank