I'm trying to unit test my project built on Angular with Karma-jasmine.
When I run the test I get this error:
Error: Unexpected request: GET assets/l10n/en.js
This is my spec file:
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();
});
});
If I delete the line httpBackend.flush();
it works properly. What am i doing wrong?