Bug: Support use in act testing API #25523 #32212
Labels
Resolution: Needs More Information
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
React version:
Main branch (as of October 21, 2022, when PR #25523 was merged).
Steps To Reproduce
Write a test that uses the use hook inside a component.
Wrap the test in act but do not await the thenable returned by act.
Observe that the test may fail or behave inconsistently due to improper task scheduling.
Link to code example:
javascript
import { act, render } from '@testing-library/react';
import React, { use } from 'react';
async function fetchData() {
return Promise.resolve('data');
}
function Component() {
const data = use(fetchData());
return
}
test('use hook in act', async () => {
await act(async () => {
render();
});
});
The current behavior
If the thenable returned by act is not awaited, tasks scheduled by use may not be flushed correctly, leading to inconsistent test behavior.
No warning is shown unless use is called, which can make debugging difficult.
The expected behavior
The act API should fully support the use hook, ensuring tasks are properly scheduled and flushed.
A warning should be shown if the thenable returned by act is not awaited, helping developers identify potential issues.
The text was updated successfully, but these errors were encountered: