angularjs - How can I mock a service that gets immediately invoked when the controller loads? -



angularjs - How can I mock a service that gets immediately invoked when the controller loads? -

i have controller grabs info service when loads.

angular.module('app').controller("mycontroller", function (myservice) { var projectid = myservice.project.id; });

this info gets set previous action in application. when karma/jasmine loads controller in fresh state service doesn't have data. i've tried mocking service in beforeeach block haven't had luck.

beforeeach(function () { var myservice = { project: { id: 'thadsfkasj' } } });

what missing?

you can mock service using angular.value. should allow inject myservice controller.

angular.module('myservicemock', []) .value('myservice', { project: { id: 'thadsfkasj' } }); beforeeach(module( 'myservicemock' //other modules or mocks include... ));

angularjs jasmine karma-jasmine

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -