Cannot use @UntilDestroy on components in unit tests
See original GitHub issueWhen unit-testing components decorated with @UntilDestroy
this decorator has no effect since at present the JIT compiler is used for unit tests in Angular and not the AOT compiler. As a result the private properties that this decorator relies on don’t exist on the components and our components behave differently under testing scenarios to real-life scenarios.
I note that in your unit tests, you do not use the real @Component
annotation, but create the scenario that the AOT compiler uses. Having experimented with the code, I think it’s possible to simply set properties directly on the target in the decorator in JIT mode to overcome this.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
After upgrading from Angular 7 to Angular 8 my pipe test ...
I am using Jest to unit test my Angular8 components. I performed upgrade from A7 where the tests passed. Now I get an...
Read more >@ngneat/until-destroy - npm Package Health Analysis | Snyk
RxJS operator that unsubscribes when Angular component is destroyed For more information about how to use this package see README.
Read more >akita-state-management/Lobby - Gitter
Now, I am trying to write unit tests for the same. But when i run the tests, i get error saying - "...
Read more >Angular Standards for 2020 - Medium
Also use it to test Storybook ui components in isolation (for which ... Write unit tests as you develop (or before; TDD) -...
Read more >ngx-take-until-destroy v5.4.0 - npm.io
Declarative way to unsubscribe from observables when the component destroyed. Installation. npm install ngx-take-until-destroy --save ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve made a sample project with a timer and have been checking whether it continues after the component is destroyed, but it seems to stop. I’m also not getting the error that @PabloDotcom reported which I have seen before. I can’t recall the tests that were breaking in my codebase as I worked around the issue in all cases. If I can locate them I’ll revert my workaround as maybe the final version of Angular has fixed this. Alternatively I might be missing a setting in angular.json since the current project has been upgraded all the way from Angular 4!
I think it would be good for your test suite to use real components rather than making something that looks like what the compiler does to check that the decorator really works in all situations
@euangoddard would it be possible to create a reproduction for us? I have a limited amount of time and I would not want to try to reproduce the problem myself.