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

fix(ngMockE2E): allow $httpBackend.passThrough() to work when ngMock is loaded #13124

Closed
wants to merge 1 commit into from

Conversation

schmod
Copy link
Contributor

@schmod schmod commented Oct 19, 2015

Allow $httpBackend.passThrough() to work normally when ngMock is loaded concurrently with ngMockE2E. This also allows one to use angular.mock.module() to write tests that depend on ngMockE2E, as module() always adds a dependency on ngMock.

Fixes #1434

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@schmod
Copy link
Contributor Author

schmod commented Oct 19, 2015

@googlebot I signed it!

…is loaded

Allow $httpBackend.passThrough() to work normally when ngMock is loaded
concurrently with ngMockE2E, as is typically the case when writing tests with
angular.mock.module()

Fixes angular#1434
@googlebot
Copy link

CLAs look good, thanks!

@schmod
Copy link
Contributor Author

schmod commented Dec 2, 2015

What does one need to do to get a PR merged around here?

@Narretz
Copy link
Contributor

Narretz commented Jan 23, 2016

Hi @schmod I see that this PR is a response to #1434

Can you give me a quick scenario where you need both ngMock and ngMockE2E in the same app?

@schmod
Copy link
Contributor Author

schmod commented Jan 23, 2016

Hi @Narretz,

For me, the passthrough is useful when I have a test fixture that cannot be easily inlined into JavaScript (such as an image).

I have an Angular directive and service that convert (user-provided) images into clickable thumbnails when they exceed a certain size.

The most straightforward (and realistic) way to test this functionality is to provide a real image as my test fixture, and actually let the browser make a real HTTP request to grab the image.

I suspect that there are also many other integration testing scenarios that could benefit from the semantics of a unit test, with occasional "real" HTTP requests thrown in. This workflow is difficult to achieve in practice, because the window.inject() function provided by angular-mocks loads ngMock, regardless of whether I ask for it (which seriously hampers the usefulness of using ngMockE2E for anything other than a strict End-To-End test).

Hope this helps! I realize that my proposed solution isn't the most ideal, but it doesn't seem like it would make things worse for anybody.

@petebacondarwin
Copy link
Contributor

LGTM - merging

@petebacondarwin petebacondarwin self-assigned this Jun 6, 2016
petebacondarwin pushed a commit that referenced this pull request Jun 6, 2016
…is loaded

Allow $httpBackend.passThrough() to work normally when ngMock is loaded
concurrently with ngMockE2E, as is typically the case when writing tests with
angular.mock.module()

Fixes #1434
Closes #13124
@mike-bresnahan
Copy link

This change had a bad side effect on protractor. Protractor no longer waits for pass through requests.

angular/protractor#3948

@mike-bresnahan
Copy link

I'm not an expert on Angular internals, but this change smells bad because it causes 2 instances of $httpBackend and dependent services (e.g. $browser) to exist and that violates the implied "all services are singletons" policy of Angular. This is bound to cause people issues (e.g. protractor).

@petebacondarwin
Copy link
Contributor

@mike-bresnahan - can you create a new issue for this. I see that the problem is that calling angular.injector(...) creates a completely new injector and that not only creates a new backend but also an inaccessible copy of the $browser service.

@mike-bresnahan
Copy link

Petebacondarwin, yes that is my understanding of the root cause as well and I have created a new issue for it.

#15593

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request Jan 12, 2017
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
petebacondarwin added a commit that referenced this pull request Jan 12, 2017
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
ellimist pushed a commit to ellimist/angular.js that referenced this pull request Mar 15, 2017
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
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.

5 participants