-
Notifications
You must be signed in to change notification settings - Fork 403
fix: surface observable errors via status instead of re-throwing #735
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
base: main
Are you sure you want to change the base?
Changes from all commits
b113bc3
776c993
74aee91
26cd552
c7d3d6a
13bfb96
91ea1ac
c6ddca8
e021670
0971021
7286c57
11286bf
0fde812
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| CLAUDE.local* | ||
| .DS_Store | ||
| npm-debug.log | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "version": "4.2.3", | ||
| "version": "4.3.0", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "main": "dist/index.umd.cjs", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,9 @@ import '@testing-library/jest-dom/extend-expect'; | |
| import { act, cleanup, render, renderHook, waitFor } from '@testing-library/react'; | ||
| import * as React from 'react'; | ||
| import { of, Subject, BehaviorSubject, throwError } from 'rxjs'; | ||
| import { useObservable } from '../src/index'; | ||
| import { useObservable, FirebaseAppProvider } from '../src/index'; | ||
| import { initializeApp } from 'firebase/app'; | ||
| import { baseConfig } from './appConfig'; | ||
|
|
||
| describe('useObservable', () => { | ||
| afterEach(cleanup); | ||
|
|
@@ -124,10 +126,46 @@ describe('useObservable', () => { | |
|
|
||
| act(() => observable$.next('val')); | ||
| expect(result.current.isComplete).toEqual(false); | ||
|
|
||
| act(() => observable$.complete()); | ||
| await waitFor(() => expect(result.current.isComplete).toEqual(true)); | ||
| }); | ||
|
|
||
| it('surfaces errors via status in non-suspense mode', async () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The #535 marquee scenario (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. Had to pair it with a |
||
| const error = new Error('I am an error'); | ||
| const observable$ = throwError(error); | ||
|
|
||
| const { result } = renderHook(() => useObservable('test-error-non-suspense', observable$, { suspense: false })); | ||
|
|
||
| await waitFor(() => expect(result.current.status).toEqual('error')); | ||
| expect(result.current.error).toEqual(error); | ||
| }); | ||
|
|
||
| it('surfaces errors via status when no suspense option is provided', async () => { | ||
| const error = new Error('default mode error'); | ||
| const observable$ = throwError(error); | ||
|
|
||
| const { result } = renderHook(() => useObservable('test-error-default-mode', observable$)); | ||
|
|
||
| await waitFor(() => expect(result.current.status).toEqual('error')); | ||
| expect(result.current.error).toEqual(error); | ||
| }); | ||
|
|
||
| it('retains last emitted data when observable errors after emitting', async () => { | ||
| const subject$ = new Subject<string>(); | ||
| const error = new Error('late error'); | ||
|
|
||
| const { result } = renderHook(() => useObservable('test-late-error', subject$, { suspense: false })); | ||
|
|
||
| act(() => subject$.next('good value')); | ||
| await waitFor(() => expect(result.current.status).toEqual('success')); | ||
| expect(result.current.data).toEqual('good value'); | ||
|
|
||
| act(() => subject$.error(error)); | ||
| await waitFor(() => expect(result.current.status).toEqual('error')); | ||
| expect(result.current.error).toEqual(error); | ||
| expect(result.current.data).toEqual('good value'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Suspense Mode', () => { | ||
|
|
@@ -328,5 +366,23 @@ describe('useObservable', () => { | |
| // if useObservable doesn't re-emit, the value here will still be "Jeff" | ||
| expect(refreshedComp).toHaveTextContent('James'); | ||
| }); | ||
| it('throws an error via FirebaseAppProvider suspense context path', () => { | ||
| const spy = vi.spyOn(console, 'error'); | ||
| spy.mockImplementation(() => {}); | ||
|
|
||
| const app = initializeApp(baseConfig, 'suspense-context-test'); | ||
| const error = new Error('context-path error'); | ||
| const observable$ = throwError(error); | ||
|
|
||
| const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
| <FirebaseAppProvider firebaseApp={app} suspense={true}> | ||
| {children} | ||
| </FirebaseAppProvider> | ||
| ); | ||
|
|
||
| expect(() => renderHook(() => useObservable('test-context-suspense-error', observable$), { wrapper })).toThrow(error); | ||
|
|
||
| spy.mockRestore(); | ||
| }); | ||
| }); | ||
| }); | ||
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.
See "Semver" in my review — the description says breaking, this says minor. Worth an explicit 4.3.0-vs-5.0.0 decision (this number only drives
expcanary versions either way).