ngneat / spectator

🦊 🚀 A Powerful Tool to Simplify Your Angular Tests
https://ngneat.github.io/spectator
MIT License
2.06k stars 178 forks source link

Spectator does not play well with `takeUntilDestroyed` #667

Open devfservant opened 1 week ago

devfservant commented 1 week ago

Is this a regression?

No

Description

The operator takeUntilDestroyed is used to complete an observable when the calling context is destroyed: https://angular.dev/api/core/rxjs-interop/takeUntilDestroyed

Please provide a link to a minimal reproduction of the bug

https://gist.github.com/devfservant/65335449c0ab8241bd9af9d084f5232a

Disclaimer: I was not able to create a working Stackblitz with Angular 18 + Jest + Spectator 😕 (here is my last attempt: https://stackblitz.com/edit/stackblitz-starters-sspm11)

Please provide the exception or error you saw

In the provided Gist, there are 3 tests.
In each of those tests, an observable is subscribed with the takeUntilDestroyed operator.
Therefore, we expect the observable's side effects to be isolated between each test.

The Gist shows that it is not the case with Spectator: there are some console.log from the first tests which appear in the 2dn & in the 3rd tests.

Please provide the environment you discovered this bug in

@angular/*: 18.2.x
@ngneat/spectator: 19.x.x
jest: 29.x.x
jest-preset-angular: 14.x.x
node: 20.10.0

Anything else?

Note: I have no issue when using @ngneat/until-destroy library
(but I want to use the new takeUntilDestroyed operator)

Do you want to create a pull request?

No

stackblitz[bot] commented 1 week ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.