feat(mock.$httpBackend): say which request was expected when unexpected request error

This commit is contained in:
Vojta Jina 2011-11-03 15:17:32 -07:00 committed by Igor Minar
parent 4aaa2f7f6b
commit 9b4efa73f9
2 changed files with 6 additions and 4 deletions

View file

@ -631,8 +631,10 @@ angular.module.ngMock.$HttpBackendProvider = function() {
return method == 'JSONP' ? undefined : xhr;
}
}
throw wasExpected ? Error('No response defined !') :
Error('Unexpected request: ' + method + ' ' + url);
throw wasExpected ?
Error('No response defined !') :
Error('Unexpected request: ' + method + ' ' + url + '\n' +
(expectation ? 'Expected ' + expectation : 'No more request expected'));
}
$httpBackend.when = function(method, url, data, headers) {

View file

@ -399,7 +399,7 @@ describe('mocks', function() {
hb.when('GET', '/url1').respond(200, 'content');
expect(function() {
hb('GET', '/xxx');
}).toThrow('Unexpected request: GET /xxx');
}).toThrow('Unexpected request: GET /xxx\nNo more request expected');
});
@ -506,7 +506,7 @@ describe('mocks', function() {
expect(function() {
hb('GET', '/url2', null, noop, {});
}).toThrow('Unexpected request: GET /url2');
}).toThrow('Unexpected request: GET /url2\nExpected GET /url1');
});