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

fix(ngMockE2E): ensure that mocked $httpBackend uses correct $browser #15601

Merged
merged 1 commit into from
Jan 12, 2017

Conversation

petebacondarwin
Copy link
Contributor

The fix from #13124 enabled ngMock and ngMockE2E to work together but
did it in a way that meant that the "real" $httpBackend service that
was used in pass-through depended upon a different $browser service
to the rest of the app.

This broke Protractor since it watches the $browser for outstanding
requests and the pass through requests were being tracked by the wrong
$browser instance.

Closes #15593

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

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

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

Does this PR introduce a breaking change?

Please check if the PR fulfills these requirements

Other information:

The fix from angular#13124 enabled ngMock and ngMockE2E to work together but
did it in a way that meant that the "real" `$httpBackend` service that
was used in pass-through depended upon a different `$browser` service
to the rest of the app.

This broke Protractor since it watches the `$browser` for outstanding
requests and the pass through requests were being tracked by the wrong
`$browser` instance.

Closes angular#15593
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


beforeEach(function() {
callback = jasmine.createSpy('callback');
angular.module('ng').config(function($provide) {
realHttpBackend = jasmine.createSpy('real $httpBackend');
$provide.value('$httpBackend', realHttpBackend);
$provide.factory('$httpBackend', ['$browser', function($browser) {
return realHttpBackend.and.callFake(function() { realHttpBackendBrowser = $browser; });
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't the following work as well (just trying to understand if I am missing something):

$provide.factory('$httpBackend', ['$browser', function($browser) {
  realHttpBackendBrowser = $browser;
  return realHttpBackend;
}]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way we would be able to be sure that the factory had been called but not that the correct httpBackend service had been called, no?

Copy link
Member

Choose a reason for hiding this comment

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

Aren't you explicitly checking about the correct service anyway?
(I am not saying you should change it, just wondering.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we check that the spy has been called so I guess you are right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But since I have a LGTM from you and Travis is green I am going to merge it as-is :-P

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.

waitForAngular does not wait for $httpBackend pass through requests
3 participants