I have experience in the testing world, particularly with TDD using tools like mocha, sinon, chai, and nodejs.
Recently, I've been finding AngularJS testing a bit challenging to grasp and implement.
Currently, I am trying to test the simplest method possible, as shown below:
/** @test {HateoasService#loadResource}*/
describe('HateoasService', function() {
let service = null;
let remoteBackend = null;
beforeEach(angular.mock.module('app'));
beforeEach(inject((HateoasService, $httpBackend) => {
remoteBackend = $httpBackend;
service = HateoasService;
}));
afterEach(function() {
remoteBackend.verifyNoOutstandingExpectation();
remoteBackend.verifyNoOutstandingRequest();
});
it('should resolve a promise with status 200', () => {
remoteBackend.when('GET', 'http://google.fr')
.respond(200, {});
service.loadResource('http://google.fr').then((res) => {
expect(res.status).toEqual(200);
remoteBackend.flush();
});
});
});
This code snippet corresponds to the following method:
loadResource(resource) {
return this.http.get(resource);
}
However, I seem to be encountering issues with httBackend flushing and receiving an error: Error: Unflushed requests: 1.
Could you provide assistance in getting this test to work correctly?