I have defined the following service in my angular app:
services.factory ( RetrieveQuotes: function () {Restangular.all returned ('quotes') getList () then (function ()), 'myService', ['Restangular', function (restangular) {return: events: {loading} {.. return {hello: 'world'}}}}}}}}}}]); And I'm writing the following imagery to test it:
Description ("MyService", function () {former (module ('MyApp')); BeforeEach (module ("restangular"); var $ httpBackend, Restangular, MS, beforeEach (in Effort (function (_ $ httpBackend_, _Restangular_, MyService) {MS = MyService; $ httpBackend = _ $ httpBackend_; Restangular = _Restangular_;})); This should be defined ("retrieveQuotes", function () {Expect (ms. RetrieveQuotes) .toBeDefined ();}); ("retrieveQuotes quote will return the array", function () {$ httpBackend. WhenGET ("Internal / Quote") Answer ({Hello: 'World'}); Ms.retrieveQuotes (); $ HttpBackend.flush ();});}); Whenever I pass the test, the first test passes but the second test creates error: run
error: unexpected request: received / internalapi / quote
What am I doing?
EDIT:
It is known that I was configuring purely . .. The privileged provider. Setup URL ("/ Internal"); . But I was calling to call internalapi / quotes . Notify me of the "/" defaults. Once I added slash / internalapi / quotes , it was all good :)
. You need to expect a GET request to tell $ httpBackend
Description ("MyService", function () {beforeEach (module ('MyApp')); BeforeEach (module ("restangular" ); Restonular, MS, beforeEach (Inject (function (_Restangular_, MyService) {MS = MyService; Restangular = _Restangular_;});; It should be defined ("retrieveQuotes", function () {Expect (ms.retrieveQuotes) ). Tobedefined ();} ("Retrieve quotas should return the quote array", injection (function ($ httpBackend) {$ httpBackend.whenGET ("Internal / Excerpt"). Response ({Hello: 'Vish And '}); / / Request to receive "internal / quotation" $ httpBackend.expectGET ("internal / quotation"); ms.retrieveQuotes (); $ httpBackend.flush ();}));}); Alternatively, you can enter your answer () on your expectGET () . I want to give the statement in in this way I do not need to define the response in every exam. Expect to get a request for
// "internalapi / quotes" $ httpBackend.expectGET ("internal / quotation"). (Hello: 'world'}); ms.retrieveQuotes (); $ HttpBackend.flush ();
No comments:
Post a Comment