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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -