Skip to content
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

fix: override providers for createComponentFactory #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stefanoww
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[X] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Overriding providers after executing createComponentFactory is impossible.

Issue Number: N/A
#337

What is the new behavior?

When user want to override providers, testing module is reinitialized with new providers.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

@stefanoww stefanoww marked this pull request as ready for review January 23, 2021 08:13
@stefanoww
Copy link
Author

stefanoww commented Jan 23, 2021

@NetanelBasal I am not sure whether that is the best approach. From that what I was able to figure out, we can not override providers after calling compileComponents. If we want to override it, we need to completely reset current configuration and create new one. That's what I have done.

I think similar problem may occur within other create-factory.ts files. If current solution will be fine I may also fix it in other places.

@stefanoww
Copy link
Author

@NetanelBasal any update with this one?

@NetanelBasal
Copy link
Member

I don't think we need to use resetTestingModule for every provider. The issue is only when using InjectionToken, right?

@stefanoww
Copy link
Author

To be honest based one the that answer from issue #337 (comment) and linked there issue from Angular repo I am not sure that problem occur only for InjectionToken. I have understood that you just can not override providers (any) when TestBed is already instantiated.

@NetanelBasal
Copy link
Member

@stefanoww
Copy link
Author

Maybe to better figure out that issue you may get into my branch and play with code and tests. What I understand as the problem there is that we just cannot override providers when the TestBed.compileComponents() is called and that what's mostly happen in beforeach block where we execute createComponentFactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants