Skip to content

Commit 87ef250

Browse files
committed
fix test warning
1 parent 13bfd8f commit 87ef250

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

reactfire/util/use-observable.test.tsx

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { useObservable } from './use-observable';
2-
import { renderHook, cleanup, act } from 'react-hooks-testing-library';
2+
import { renderHook, act } from '@testing-library/react-hooks';
33
import { of, Subject, Observable, observable } from 'rxjs';
44
import { delay } from 'rxjs/operators';
5-
import {
6-
render,
7-
waitForElement,
8-
getByTestId,
9-
queryByTestId
10-
} from 'react-testing-library';
5+
import { render, waitForElement, cleanup } from '@testing-library/react';
116
import { ReactFireOptions } from '..';
127
import * as React from 'react';
138
import 'jest-dom/extend-expect';
@@ -86,40 +81,20 @@ it('works with Suspense', async () => {
8681
expect(queryByTestId(fallbackComponentId)).toBeNull();
8782
});
8883

89-
it('updates the component as the observable emits new values', async () => {
90-
const observableFirstValue = 'a';
84+
it('emits new values as the observable changes', async () => {
85+
const startVal = 'start';
86+
const values = ['a', 'b', 'c'];
9187
const observableSecondValue = 'b';
9288
const observable$ = new Subject();
93-
const actualComponentId = 'actual-component';
94-
const fallbackComponentId = 'fallback-component';
95-
96-
const FallbackComponent = () => (
97-
<h1 data-testid={fallbackComponentId}>Fallback</h1>
98-
);
99-
100-
const Component = () => {
101-
const val = useObservable(observable$, 'test-suspense');
102-
return <h1 data-testid={actualComponentId}>{val}}</h1>;
103-
};
10489

105-
const { queryByTestId, getByTestId } = render(
106-
<React.Suspense fallback={<FallbackComponent />}>
107-
<Component />
108-
</React.Suspense>
109-
);
110-
111-
act(() => observable$.next(observableFirstValue));
112-
await waitForElement(() => getByTestId(actualComponentId));
113-
114-
// check that the value matches
115-
expect(getByTestId(actualComponentId)).toHaveTextContent(
116-
observableFirstValue
90+
const { result } = renderHook(() =>
91+
useObservable(observable$, 'test', startVal)
11792
);
11893

119-
act(() => observable$.next(observableSecondValue));
94+
expect(result.current).toEqual(startVal);
12095

121-
// check that the component was updated with the new value
122-
expect(getByTestId(actualComponentId)).toHaveTextContent(
123-
observableSecondValue
124-
);
96+
values.forEach(value => {
97+
act(() => observable$.next(value));
98+
expect(result.current).toEqual(value);
99+
});
125100
});

0 commit comments

Comments
 (0)