我正在尝试使用 Jasmine 单元测试规范文件测试 AngularJS 控制器。我的方法是在以下测试中使用 $httpBacked:
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);
});
});
我插入了 expect(true).toBe(true) 只是为了让测试执行并失败,即使它没有触及角度控制器。当我尝试使用 jasmine-headless-webkit 运行测试时,我收到以下错误:
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
是否有关于如何纠正此错误并执行微不足道的测试的任何提示?