Monday, 15 April 2013

javascript - AngularJS and Jasmine: mocking services -


I'm joking about the dependency of the following service "broadcasters" on the service "push server".

  Angular Modules ('Broadcaster', ['Push Services']); ('Broadcaster'), service ('Broadcaster', ['$ Rootscope', '$ log', 'snappush', function ($ Rootscope, $ log, snapshot) {//. Content}};}  
  Description ('Test Broadcaster Service', Function () {'Strict Use'; var Broadcast Service, MockShuxeweva; First (module ('broadcasters')) first (injection (function ($ injector) {broadcaster service = $ injector.get ('broadcaster'); mockPushService = {getSomething: function (Return 'mockReturnValue';}}; Module (function ($ rendered) {$. Value ('satnetpush', mockupushva);});});) (This' non-empty broadcaster object Should return ', function () {Expect (broadcaster service) no. To banal ();});  

});

I get the error That's the usual "unknown provider":

  Fmtmoz S 1.9.8 (Linux) Test Broadcasters should return Rvice to a non-empty broadcaster object FAI LED error: [$ Injector: unpr] Unknown Provider: $ pusherProvider & lt; - $ pusher & lt; - satnetPush & lt; - Broadcasters http://errors.angularjs.org/1.3.14/ $ Injector / effect? P = 0% 24 Power Provider% 20% 3C-% 20% 24 Power% 20% 3C-20 20% SecurePush% 20% 3C-% 20broadcaster  

What do I do Am I wrong? How can I inject an dependence instead?

The key is to provide your fake service before you receive $ service after trial by injector then 'Satnetpush' will be present:

  Description ('Test Broadcaster Service', Function () {'Strict Use'; var Broadcast Service, MockPues Service; First Every (Function () (Modules (' Broadcaster (Providing) () (Module (Function ($ $) {MockPsuseWire = {getSomething: Function () {Return 'Mock Retailwall';}}; $ P Price ('setpush', mockupusaveer;)); inject (function ($ injector) {broadcaster service = $ injector.get ('broadcaster');})}); ('return to non-empty broadcaster object Should do ', function () {expectations (broadcaster service) .not.toBeNull ();});});  

this one


No comments:

Post a Comment