Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngMocks): Describe unflushed http requests #15928

Merged
merged 3 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,7 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
}
}

handleResponse.description = method + ' ' + url;
return handleResponse;

function handleResponse() {
Expand Down Expand Up @@ -1884,7 +1885,9 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
$httpBackend.verifyNoOutstandingRequest = function(digest) {
if (digest !== false) $rootScope.$digest();
if (responses.length) {
throw new Error('Unflushed requests: ' + responses.length);
var unflushedDescriptions = responses.map(function(res) { return res.description; });
throw new Error('Unflushed requests: ' + responses.length + '\n ' +
unflushedDescriptions.join('\n '));
}
};

Expand Down
20 changes: 18 additions & 2 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,8 @@ describe('ngMock', function() {

expect(function() {
hb.verifyNoOutstandingRequest();
}).toThrowError('Unflushed requests: 1');
}).toThrowError('Unflushed requests: 1\n' +
' GET /some');
});


Expand All @@ -1690,8 +1691,23 @@ describe('ngMock', function() {

expect(function() {
hb.verifyNoOutstandingRequest();
}).toThrowError('Unflushed requests: 1');
}).toThrowError('Unflushed requests: 1\n' +
' GET /some');
}));


it('should describe multiple unflushed requests', function() {
hb.when('GET').respond(200);
hb.when('PUT').respond(200);
hb('GET', '/some', null, noop, {});
hb('PUT', '/elsewhere', null, noop, {});

expect(function() {
hb.verifyNoOutstandingRequest();
}).toThrowError('Unflushed requests: 2\n' +
' GET /some\n' +
' PUT /elsewhere');
});
});


Expand Down