我正在尝试使用Karma-jasmine对使用Angular构建的项目进行单元测试。
当我运行测试时,我收到此错误:
Error: Unexpected request: GET assets/l10n/en.js
这是我的spec文件:
describe('test Overview Factory', function() {
var overviewFactory, api_url, $q, httpBackend, $scope, response;
beforeEach(angular.mock.module('app'));
beforeEach(inject(function(_OverviewFactory_, _$q_, _$httpBackend_, _$rootScope_, API_URL) {
$q = _$q_;
api_url = API_URL;
overviewFactory = _OverviewFactory_;
httpBackend = _$httpBackend_;
$scope = _$rootScope_.$new();
httpBackend.whenGET('url', undefined, {
Authorization: "Bearer token"
}).respond();
}));
// Verify our factory exists
it('should be defined', function() {
expect(overviewFactory).toBeDefined();
});
it('should gets totals from api', function() {
httpBackend.expectGET('url').respond(200);
httpBackend.flush();
});
});
如果我删除了行httpBackend.flush();
,它就能正常工作。我做错了什么?