New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support adding mock modules to Angular 2 applications #3092
Comments
@juliemr are we planning to support mock for angular 2? If yes, when? If we uses hybrid mode, will mock continue to work at the meantime? |
@jlin412 yes, eventually, but it will require investigation and careful thinking about how it works in both aot and non-aot. If you use hybrid it will continue to work for the ng1 bits. Everyone else - please use github's emoji response to +1 issues. Adding comments makes it difficult to parse real progress. I'll be removing these comments so that this is readable. Thanks! |
@juliemr Do we have an ETA on mock implementation for angular 2? |
FROM: http://stackoverflow.com/questions/36354233/protractor-mocking-backend-with-angular2-on-api-request.
Therefore, I created an E2E test environment using docker-compose, but i feel it's exaggerated implementation. Do you currently have best practices? |
I ran into the same issue for mocking my backend calls. As we use connect middleware to run our app, I created a plugin that allows you to mock your angular 1 and 2 http request. https://mdasberg.github.io/ng-apimock/ maybe you can use it. |
I'm not sure the machinism by which to do this but I think the naive approach to install mock modules would be the following: Protractor would somehow override both of these methods:
In their place would be a simple wrapper which constructs a new ngModule and provides the modules we want to mock out (below is pseudo code of what it would look like):
|
Any idea if there is a planned release for this feature? |
+1 for this feature. We need mocks in the e2e tests in Angular 2+ applications! |
Angular 2+ is growing, so this feature is becoming pretty urgent :) |
Yeah is absolutely crucial to our workflow at the moment. |
We already are at angular5 and still unable to mock http in e2e specs 😕 (@tauil small world, huh?) |
Here are common uses I need addMockModule for .
For custom services: we could follow the httpclient template approach. Implementing (1) would potentially solve this also.
|
When will it be implemented? |
Could really do with this! |
This a must-have feature, how can it be two years old?! As a work-around, you can use jswiremock to stub out the back end calls. I have written up some instructions here: https://gist.github.com/jamescookie/f7b854226ca1e133d1b7b2798095b7f4 |
Another alternative is nock. |
You can use ng-apimock which is already present on the protractor site. There is a great blog post about it here You can use it for AngularJs and Angular apps |
This feature is crucial enough that I think it should be part of core protractor, even if ng-apimock was just included into protractor's core libraries. |
Trying to thumbs up as much as I can, what is the progress on this feature? It's a heavy blocker at the moment. |
Seriously, has protractor just been abandoned for Angular? |
So this is partly doable without any changes to protractor or angular today. You can create a "mock" configuration to I also outline the steps required in my answer to an SO question here: https://stackoverflow.com/questions/39942118/how-to-inject-different-service-based-on-certain-build-environment-in-angular2/51772549#51772549 It isn't as easy/customizable as it was in Angular 1 (e.g. you can't add different mock services for different tests) but once the scaffolding is up and running adding and removing mock services should be pretty straightforward. |
Summary of a quick - clean - library-less way to handle this here: |
Is there any update on this? @jlin412 you said that it will require investigation and careful thinking - have you started on this? |
@katiesandford, I believe the approach detailed at here will accommodate most testing situations in this setup. If it does not, I would love to know what those outliers are so I can think about those for future situations |
@gabrieldoty With this approach, you can mock at service level but not at http level if I understand well. |
@gaeljw great points! I can see some rather clunky ways to handle the dynamic mocks, but no question a dynamic solution would be preferable! My application only uses a single dataservice class to handle all HTTP requests, so it is fairly easy to swap out that one service. But that is not nearly as universal as a true http mock.. Thanks for those thoughts! |
any news about this? It looks like Protractor development is no longer that active... |
any updates? |
Mocking modules would help to get around #4300 |
Wow, this ticket is almost 4 years old now! Are there any updates? |
Any news? |
Using ng-apimock currently, but is there an update to this? |
Currently it is not possible to add mock modules for Angular 2 applications.
This issue reflects the TODO posted here.
And, to cross-reference the relevant SO post: http://stackoverflow.com/questions/36354233/protractor-mocking-backend-with-angular2-on-api-request.
Thank you.
The text was updated successfully, but these errors were encountered: