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 1 commit
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
8 changes: 7 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,12 @@ 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 = [];
for (var i = 0, len = responses.length; i < len; ++i) {
unflushedDescriptions.push(responses[i].description);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: var unflushedDescriptions = responses.map(function(res) { return res.description; }); is shorter.

throw new Error('Unflushed requests: \n ' +
unflushedDescriptions.join('\n '));
}
};

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

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


Expand All @@ -1690,7 +1690,7 @@ describe('ngMock', function() {

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

Expand Down