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


I have a controller that quickly captures some data from a service when loaded.

  Angular.module ('app'). Controller ("microcontroller", function (MySwive) {var project id = myservice.project.id;});  

This data is set in the previous action in the application. So when the Karma / Jasmin has loaded this controller in a fresh state, then this service does not have this data. I had ridiculed this service before, every block, but no fate has happened.

first each (function () {var myService = {project: {id: 'thadsfkasj'}}});

What am I missing?

You can duplicate your service by using angular.value After this, you should allow in your controller to inject myService .

  angular.module ('myServiceMock', []) .value ('myService', {project: {Id: 'thadsfkasj'}}); First of all (modules ('myServiceMock' // other modules to include or mocks ...));  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -