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

Conversation

jakewins
Copy link
Contributor

@jakewins jakewins commented Apr 20, 2017

The current implementation of $httpBackend.verifyNoOutstandingRequest
gives an integer number describing how many requests are unflushed.

While it's superficially easy to solve test errors from that message
by simply adding an additional $httpBackend.flush(), if a developer
is truly not expecting the code to make further requests this is
not ideal.

This change explicitly prints out which additional requests remain
unflushed in the error message, helping her determine if the code
needs changing, or if an additional flush is appropriate.

Before this change:

Unflushed requests: 1

After this change:

Unflushed requests:
  GET /some

Closes #10596

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

A feature improving the output of ngMocks "Unflushed requests" error message.

What is the current behavior? (You can also link to an open issue here)

The error message includes the number of requests remaining unflushed.

What is the new behavior (if this is a feature change)?

The error message now includes a brief description of which requests remain unflushed.

Does this PR introduce a breaking change?

No - unless the error messages are considered public API.

Please check if the PR fulfills these requirements

Other information:

The current implementation of $httpBackend.verifyNoOutstandingRequest
gives an integer number describing how many requests are unflushed.

While it's superficially easy to solve test errors from that message
by simply adding an additional $httpBackend.flush(), if a developer
is truly not expecting the code to make further requests this is
not ideal.

This change explicitly prints out which additional requests remain
unflushed in the error message, helping her determine if the code
needs changing, or if an additional flush is appropriate.

Before this change:

    Unflushed requests: 1

After this change:

    Unflushed requests:
      GET /some

Closes angular#10596
@jakewins jakewins force-pushed the describe-unflushed branch from 548c0a0 to 7bd05f7 Compare April 20, 2017 17:01
@jakewins
Copy link
Contributor Author

The test failure from travis seems, to my novice eyes, unrelated - it looks like a flaky test around ngHide?

@Narretz
Copy link
Contributor

Narretz commented Apr 20, 2017

Hi @jakewins , thanks for the PR. I think this is a good change. Can you change the output so that the number of unflushed requests is still included? And expand the tests to include more than one unflushed request?

@jakewins
Copy link
Contributor Author

@Narretz for sure. Is the preferred approach to git --amend, or to add additional commits to the PR?

@Narretz
Copy link
Contributor

Narretz commented Apr 20, 2017

@jakewins Additional commits are fine, I will squas wehn I merge

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.

@jakewins
Copy link
Contributor Author

@Narretz @gkalpak fixed!

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

LGTM

@Narretz Narretz merged commit 080357e into angular:master Apr 21, 2017
@Narretz Narretz modified the milestones: 1.6.5, 1.6.x Apr 21, 2017
Narretz pushed a commit that referenced this pull request Apr 21, 2017
The current implementation of $httpBackend.verifyNoOutstandingRequest
gives an integer number describing how many requests are unflushed.

While it's superficially easy to solve test errors from that message
by simply adding an additional $httpBackend.flush(), if a developer
is truly not expecting the code to make further requests this is
not ideal.

This change explicitly prints out which additional requests remain
unflushed in the error message, helping her determine if the code
needs changing, or if an additional flush is appropriate.

Before this change:

    Unflushed requests: 1

After this change:

    Unflushed requests: 1
      GET /some

Closes #10596
Closes #15928
@jakewins jakewins deleted the describe-unflushed branch April 21, 2017 17:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngMock $httpBackend should keep a list of the received calls to debug tests
4 participants