Vorrei passare alcune delle mie richieste http e non deriderle nel mio test di unità, ma quando provo a chiamare il metodo passThrough(), un errore di metodo mancante è lanciato:
"TypeError: Object # has no method 'passThrough'".
Qualcuno sa come posso risolvere il problema per favore?
V'è il mio codice:
'use strict';
describe('Controller: MainCtrl', function() {
// load the controller's module
beforeEach(module('w00App'));
var scope, MainCtrl, $httpBackend;
// Initialize the controller and a mock scope
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
$httpBackend = _$httpBackend_;
$httpBackend.expectGET('http://api.some.com/testdata.json').passThrough();
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl', {
$scope: scope
});
}));
});
Come spiegato in [documentazione] (http://docs.angularjs.org/api/ngMock.$httpBackend): * Durante il test di unità, vogliamo che i nostri test di unità per eseguire in modo rapido e non hanno dipendenze esterne quindi non vogliamo inviare richieste XHR o JSONP a un vero server *. Il servizio $ httpBackend utilizzato nei test unitari non può passare. Il $ httpBackend utilizzato dal test end-to-end può, tuttavia. –
Ciò rende le direttive di test con i modelli esterni più difficili del necessario, non credi? – SimplGy