angularjs - Unknown Provider when testing a modal dialog -
preface : i'm quite new angular , new unit-testing. gentle.
i'm trying run unit tests on controller bootstrap modal window.
when initiating modal passing through object called thisversion
:
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 shares controller
instantiated calling method on thisversion
thisversion.getlist('shares').then(function(result){ $scope.shares = result; });
thisversion
being passed in controller dependency, , works expected.
the issue, however, can't seem inject test suites. keep getting error
error: [$injector:unpr] unknown provider: thisversionprovider <- thisversion
this (most of) 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 list of shares', function(){ expect(thisversion.getlist).not.tobe('undefined'); });
i know going have mock call api thisversion.getlist()
i'm concerned getting test suite recognise thisversion
you need inject thisversion
into $controller, seeing how it's resolved value in $modal.open.
var modalinstance = $modal.open({ templateurl: 'app/shares/views/shares-dialogue.tpl.html', controller: 'sharesctrl', resolve:{ // resolved properties available di, controller. thisversion:function(){ return thisversion; } } });
beforeeach(module('app')); beforeeach(inject(function ($controller, $rootscope, _thisversion_) { scope = $rootscope.$new(); controller = $controller('sharesctrl', { $scope: scope, thisversion: _thisversion_ /** inject service _into_ controller **/ }); }));
Comments
Post a Comment