Skip to content

Commit

Permalink
Add test for use hook with forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
hansottowirtz committed Mar 29, 2023
1 parent c383035 commit 10e2b33
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/react-reconciler/src/__tests__/ReactUse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1472,4 +1472,32 @@ describe('ReactUse', () => {
assertLog(['Hi']);
expect(root).toMatchRenderedOutput('Hi');
});

it('basic use(promise) with forwardRefs', async () => {
const promiseA = Promise.resolve('A');
const promiseB = Promise.resolve('B');
const promiseC = Promise.resolve('C');

const Async = React.forwardRef((props, ref) => {
const text = use(promiseA) + use(promiseB) + use(promiseC);
return <Text text={text} />;
});

function App() {
return (
<Suspense fallback={<Text text="Loading..." />}>
<Async />
</Suspense>
);
}

const root = ReactNoop.createRoot();
await act(() => {
startTransition(() => {
root.render(<App />);
});
});
assertLog(['ABC']);
expect(root).toMatchRenderedOutput('ABC');
});
});

0 comments on commit 10e2b33

Please sign in to comment.