2016-02-18 1 views
0

J'essaye de tester une usine mais je reçois une erreur bizarre J'ai regardé autour mais je n'ai pas pu trouver un problème semblable. Je fais mal?Undefined: value.push (new Ressource (item)

TypeError: 'undefined' is not a function (evaluating 'value.push(new Resource(item))')

Utilisation angluarjs v1.3.20

factory.js

'use strict'; 

//Business service used for communicating with the articles REST endpoints 
angular.module('businesses').factory('Business', ['$resource', 
    function ($resource) { 
     return $resource('api/businesses/:businessId', { 
      businessId: '@_id' 
     }, { 
      update: { 
       method: 'PUT' 
      } 
     }); 
    } 
]); 

test.js

describe('My Service', function() { 


    // Then we can start by loading the main application module 
    beforeEach(module(ApplicationConfiguration.applicationModuleName)); 

    afterEach(inject(function($httpBackend){ 
     //These two calls will make sure that at the end of the test, all expected http calls were made 
     $httpBackend.verifyNoOutstandingExpectation(); 
     $httpBackend.verifyNoOutstandingRequest(); 
    })); 

    it('mock http call', inject(function($httpBackend, Business) { 
     var resource = new Business({ 
      _id:'abcd' 
     }); 
     var arraya = [{ 
      _id:'abcd' 
     }, { 
      _id:'abcde' 
     }]; 
     //Create an expectation for the correct url, and respond with a mock object 
     $httpBackend.expectGET('api/businesses/abcd').respond(200, arraya) 

     resource.$query(); 

     //Because we're mocking an async action, ngMock provides a method for us to explicitly flush the request 
     $httpBackend.flush(); 

     //Now the resource should behave as expected 
     console.log(resource); 
     //expect(resource.name).toBe('test'); 
    })); 

}); 

xxxxxxxxxxxxxxxxxxxxxxxxxxx

+0

Cela peut être stupide, mais ne devriez-vous pas mettre le 'expectGET' après le' flush() '? – ppseprus

Répondre

-1

ne devrait pas vous attendre seulement après que vous rincée?

resource.$query(); 

//Because we're mocking an async action, ngMock provides a method for us to explicitly flush the request 
$httpBackend.flush(); 

//Create an expectation for the correct url, and respond with a mock object 
$httpBackend.expectGET('api/businesses/abcd').respond(200, arraya); 
+0

Non. Quand je change l'ordre, je reçois 'Erreur: Demande inattendue: GET api/entreprises/abcd' –

+0

Eh bien .. Je vous ai dit, Il pourrait être stupide: P Désolé, je ne pouvais pas aider – ppseprus

+0

Merci pour cet effort. Va mettre à jour angulaire et voir si cela fait l'affaire. –