mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 15:24:43 +00:00
feat(mock.$httpBackend): say which request was expected when unexpected request error
This commit is contained in:
parent
4aaa2f7f6b
commit
9b4efa73f9
2 changed files with 6 additions and 4 deletions
6
src/angular-mocks.js
vendored
6
src/angular-mocks.js
vendored
|
|
@ -631,8 +631,10 @@ angular.module.ngMock.$HttpBackendProvider = function() {
|
||||||
return method == 'JSONP' ? undefined : xhr;
|
return method == 'JSONP' ? undefined : xhr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw wasExpected ? Error('No response defined !') :
|
throw wasExpected ?
|
||||||
Error('Unexpected request: ' + method + ' ' + url);
|
Error('No response defined !') :
|
||||||
|
Error('Unexpected request: ' + method + ' ' + url + '\n' +
|
||||||
|
(expectation ? 'Expected ' + expectation : 'No more request expected'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$httpBackend.when = function(method, url, data, headers) {
|
$httpBackend.when = function(method, url, data, headers) {
|
||||||
|
|
|
||||||
4
test/angular-mocksSpec.js
vendored
4
test/angular-mocksSpec.js
vendored
|
|
@ -399,7 +399,7 @@ describe('mocks', function() {
|
||||||
hb.when('GET', '/url1').respond(200, 'content');
|
hb.when('GET', '/url1').respond(200, 'content');
|
||||||
expect(function() {
|
expect(function() {
|
||||||
hb('GET', '/xxx');
|
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() {
|
expect(function() {
|
||||||
hb('GET', '/url2', null, noop, {});
|
hb('GET', '/url2', null, noop, {});
|
||||||
}).toThrow('Unexpected request: GET /url2');
|
}).toThrow('Unexpected request: GET /url2\nExpected GET /url1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue