Skip to content
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

Bug: Support use in act testing API #25523 #32212

Open
Mohammed-Karim226 opened this issue Jan 24, 2025 · 1 comment
Open

Bug: Support use in act testing API #25523 #32212

Mohammed-Karim226 opened this issue Jan 24, 2025 · 1 comment
Labels
Resolution: Needs More Information Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@Mohammed-Karim226
Copy link

React version:
Main branch (as of October 21, 2022, when PR #25523 was merged).

Steps To Reproduce

  1. Write a test that uses the use hook inside a component.

  2. Wrap the test in act but do not await the thenable returned by act.

  3. 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

{data}
;
}

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.

@Mohammed-Karim226 Mohammed-Karim226 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jan 24, 2025
@eps1lon
Copy link
Collaborator

eps1lon commented Jan 24, 2025

Can you provide a cloneable repro? An act() that's async and not awaited should trigger a warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs More Information Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants