spectator
spectator copied to clipboard
fix: override providers for createComponentFactory
PR Checklist
Please check if your PR fulfills the following requirements:
- [X] The commit message follows our guidelines: https://github.com/ngneat/spectator/blob/master/CONTRIBUTING.md#commit
- [X] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
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
@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.
@NetanelBasal any update with this one?
I don't think we need to use resetTestingModule
for every provider. The issue is only when using InjectionToken
, right?
To be honest based one the that answer from issue https://github.com/ngneat/spectator/issues/337#issuecomment-689657302 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.
Now I'm not sure what's the issue. Works for me - https://github.com/ngneat/bind-query-params/blob/master/projects/ngneat/bind-query-params/src/lib/lib.spec.ts#L115
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.