Tuesday, 15 May 2012

karma jasmine - testing ui-router stateprovider 'resolve:' values -


I'm using jasmine + karma to run the following code ... and get the following error:

<<< Code> required {then: function, hold: function, finally: function} equal 123. Can someone help me to understand why I'm sure of your promise. Thanks 'Strict Use'; Angular Modules ('Example', ['ui.router']). Conflict (function ($ state provider) {$ stateProvider .state ('stateOne', {url: '/ stateOne', solve: {cb: function ($ Q) {var deferred = $ q.defer (); deferred Resolve (123); refund suspended.promis;}}, controller: function ($ radius, CB) {console.log ('in controller', CB);}, TemplateUrl: 'stateOne.html'})}). Run (function ($ template cache) {$ templateCache.put ('stateOne.html', 'this is the content of the template');}); Describe ('main test', function () (first) (function () (module ('example');}) ('basic test', description of the function ($ rootscope)) (this ('state' 'Injection (function $ rootscope, $ state, $ injector, $ compilation) {var config = $ state.get (' stateOne '); Hopefully (config.url) .toEqual (' / stateOne '); $ compilation (' & Lt; div ui-view / & gt; '($ rootsecope); $ rootsecope. $ Digest (); hopefully ($ injector.invoke (config.resolve.cb)). ToEqual (123);})) ;});}); Well, explained this to Nicos with some help (via email), whose blog contains

I found at :.

Here is a brief example of how resolution values ​​are tested in ui.router, where the value is $ http.

  Angular Modules ('Example', ['ui.router']) .Feature ('clipboard', function ($ http) {return {get: function (args) {return $ http.get ('/ db / clipboard'); }};}) Config (function ($ state provider) {$ stateProvider .state ('stateOne', {Hull: {cb: function (clipboard)} return clipboard .get ();}}})}}); Describe ('main test', function () (function) (module ('example');}); ('stateon', injection (function ($ state, $ injector, $ httpBackend) {$ httpBackend } ('/ Db / clipboard'). Answer ({a: 1}); $ injector.invoke ($ state.get ('stateOne'). ['Cb']. Then solve (race) {Console} .log ('* res', res.data);}) hold (function (mistake) {console.log ('* err', err);}); $ httpBackend.flush ();}) ); AfterEach (Injection (function ($ httpBackend) {$ httpBackend.verifyNoOutstandingExpectation (); $ httpBackend.verifyNoOutstandingRequest ();})))}};  

No comments:

Post a Comment