Sto tentando di testare un controller AngularJS con un file di specifiche del test dell'unità Jasmine. Il mio approccio è quello di utilizzare $ httpBacked, nel seguente test:
describe('SubmissionsController', function() {
var minimal_mock_response = [ { id: 1 } ];
var scope, routeParams, $httpBackend;
beforeEach(module('submissionServices'));
beforeEach(inject(function($_httpBackend_, $rootScope) {
scope = $rootScope.$new();
$httpBackend = $_httpBackend_;
$httpBackend.expectGET('/submissions').respond(minimal_mock_response);
routeParams = {};
}));
it('passes a trivial test', function() {
expect(true).toBe(true);
});
});
ho inserito l'aspetta (vero) .toBe (true) solo per ottenere il test da eseguire e non riescono, anche se non tocca il angolare controller. Quando io tento di eseguire il test con il gelsomino senza testa-webkit, ho visualizzato il seguente errore:
jasmine-headless-webkit spec/javascripts/SubmissionsControllerSpec.js
Running Jasmine specs...
F
FAIL: 1 test, 1 failure, 0.011 secs.
Submissions controllers SubmissionsController passes a trivial test. (XXX/spec/javascripts/SubmissionsControllerSpec.js:18)
Error: Unknown provider: $_httpBackend_Provider <- $_httpBackend_
Test ordering seed: --seed 9254
Esistono suggerimenti su come posso correggere questo errore e fare il test banale eseguire?
risolto questo problema, grazie! – oxirane
L'unico problema qui è stato un refuso. Dovrebbe essere stato \ _ $ httpBackend \ _, non $ _httpBackend_. La risposta qui sotto è preferibile a questa. – user553086
@RichardMorgan Hai ragione. Ho aggiornato la mia risposta. +1 a ghiden – dnc253