-
Notifications
You must be signed in to change notification settings - Fork 27k
fix(core): Prevent an error on cleanup when an rxResource stream threw before returning an Observable
#63342
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
Conversation
| it('should cleanup without error when the stream function threw an error', async () => { | ||
| const injector = Injector.create({ | ||
| providers: [], | ||
| parent: TestBed.inject(Injector), | ||
| }); | ||
| const appRef = TestBed.inject(ApplicationRef); | ||
| const res = rxResource({ | ||
| stream: () => { | ||
| throw 'oh no'; | ||
| }, | ||
| injector, | ||
| }); | ||
| await appRef.whenStable(); | ||
|
|
||
| // What now? :( | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| it('should cleanup without error when the stream function threw an error', async () => { | |
| const injector = Injector.create({ | |
| providers: [], | |
| parent: TestBed.inject(Injector), | |
| }); | |
| const appRef = TestBed.inject(ApplicationRef); | |
| const res = rxResource({ | |
| stream: () => { | |
| throw 'oh no'; | |
| }, | |
| injector, | |
| }); | |
| await appRef.whenStable(); | |
| // What now? :( | |
| }); | |
| it('should cleanup without error when the stream function threw an error', async () => { | |
| const appRef = TestBed.inject(ApplicationRef); | |
| const res = rxResource({ | |
| stream: () => { | |
| throw 'oh no'; | |
| }, | |
| injector: appRef.injector, | |
| }); | |
| await appRef.whenStable(); | |
| }); |
This basically throws today, but shouldn't with your fix.
|
From my understanding, this is actually not what happens. Because if you look at the StackBlitz from my issue, the code itself doesn't throw. The resource is created and is in an error state. |
|
What I mean is that the test fails because a runtime error is thrown while awaiting. With your fix the test should pass without any expectations. |
…threw before returning an `Observable` Before this commit, it was wrongly assumed that the stream subscription could not be `undefined`. Fixes angular#63341
3b1dfab to
4a1e0cd
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Before this commit, it was wrongly assumed that the stream subscription could not be
undefined.Fixes #63341
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #63341
What is the new behavior?
No error
Does this PR introduce a breaking change?
Other information
Please suggest a way to write this test :(