angularjs - How can I access my service from module setup in Angular Jasmine Test? -
i have next in jasmine test angular...
beforeeach(module('app')); beforeeach(module('app.services')); beforeeach(module(function ($provide, config) { reservationcallerjquery = { reservebooking: function (reservationrequestdto, reservebookingsuccess) { dojquerypost(reservationrequestdto.item, "i need value config class", reservebookingsuccess); } $provide.value("reservationcaller", reservationcallerjquery); }));
but error:
error: [$injector:modulerr] failed instantiate module function ($provide,config) due to: error: [$injector:unpr] unknown provider: config
so how set string of stub config? (the config lives in 'app.services')...i think need there how?
you'r missing inject, can inject service, constant, controller etc.. in 1 of 2 ways :
in inject callback can retrieve $injector , want.
var myservice, location; beforeeach(function() { inject(function($injector) { myservice = $injector.get('myservice'); location = $injector.get("$location"); }); });
or
get service directly, can add together _servicename_ resolve servicename allow utilize servicename var in test :
var scope, $rootscope, $location; beforeeach(inject(function (_$rootscope_, _$location_) { scope = $rootscope.$new(); $rootscope = _$rootscope_; $location = _$location_ }));
my typical test setup :
beforeeach(module('myapp')); beforeeach(module('myapp.services')); beforeeach(module('myapp.controllers')); var ctrl, scope, myservice; beforeeach(inject(function ($rootscope, $controller, $injector) { scope = $rootscope.$new(); ctrl = $controller('myctrl', {$scope: scope}); myservice = $injector.get('myservice'); }));
angularjs jasmine angular-mock
No comments:
Post a Comment