fix(core): Prevent an error on cleanup when an rxResource stream threw before returning an Observable#63342
fix(core): Prevent an error on cleanup when an rxResource stream threw before returning an Observable#63342wartab wants to merge 1 commit intoangular:mainfrom
rxResource stream threw before returning an Observable#63342Conversation
| 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.
| 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 :(