Preface : I'm quite new to Angular and very new to unit-testing. Be gentle.
I'm trying to run unit tests on a controller for a bootstrap modal window.
When initiating the modal I am passing through an object called thisVersion
like so :
function showShareDialog(thisVersion){
var modalInstance = $modal.open({
templateUrl: 'app/shares/views/shares-dialogue.tpl.html',
controller: 'SharesCtrl',
resolve:{
thisVersion:function(){
return thisVersion;
}
}
});
modalInstance.result.then(function (validated) {
// .. more code
});
}
As soon as the Shares Controller
is instantiated I am calling a method on thisVersion
thisVersion.getList('shares').then(function(result){
$scope.shares = result;
});
thisVersion
is being passed in to the controller as a dependency, and that all works as expected.
The issue, however, is that I can't seem to inject it into my test suites. I keep getting this error
Error: [$injector:unpr] Unknown provider: thisVersionProvider <- thisVersion
This is (most of) my test suite :
var scope, controller, thisVersion;
beforeEach(module('app'));
beforeEach(inject(function ($controller, $rootScope, _thisVersion_) {
scope = $rootScope.$new();
controller = $controller('SharesCtrl', {
$scope: scope
});
thisVersion = _thisVersion_;
}));
it('should get a list of all shares', function(){
expect(thisVersion.getList).not.toBe('undefined');
});
I know I am going to have to mock the call to the Api from thisVersion.getList()
but for now I'm just concerned with getting the test suite to recognise thisVersion
Aucun commentaire:
Enregistrer un commentaire