I'm using unit-testing in my angularJS application. Here's a test spec I have for a service:
describe('service', function () {
var service = {};
var $httpBackend;
beforeEach(module('myApp'));
beforeEach(inject(function (_service_, _$httpBackend_) {
service = _service_;
$httpBackend = _$httpBackend_;
}));
it('should return test message', function () {
var response;
var test = "This is a test";
$httpBackend.when('GET', '/api/Account/GetTest')
.respond(200, test);
service.getTest().then(function (data) {
response = data;
});
expect(response).toEqual(test);
});
});
And, here's the getTest
function in my service:
var getTest = function () {
return $http.get("api/Account/GetTest");
};
Why am I getting the following error:
Error: Unexpected request: GET api/Account/GetTest
I also figured if I remove the slash from the url in my spec, the error will change to this (and I have no idea why):
Error: Unexpected request: GET /app/views/login.html