Open
Description
Describe the bug
waitFor
and functions that use it behind-the-scenes like findBy
can produce inconsistent results when fake timers are enabled globally versus per-test. This specifically affects tests that render components with async mount effects that trigger state updates. When fake timers are enabled globally in jest.config.js
, the test behavior may differ compared to enabling them within individual test files using jest.useFakeTimers()
.
Example:
const MyComponent = () => {
const [count, setCount] = React.useState(0);
const myPromise = async () => {
const response = await new Promise<number>((resolve) => resolve(1));
setCount(response);
};
React.useEffect(() => {
myPromise();
}, []);
return count > 0 && <Text testID="count">{count}</Text>;
};
Expected behavior
Tests produce the same result independently to enable fake timers globally.
Steps to Reproduce
A couple of branches have been created to demonstrate this case:
- Case: Test fails when enabling fake timers globally
- Case: Test passes when enabling fake timers on the test
Screenshots
Case: Test fails when enabling fake timers globally

Case: Test passes when enabling fake timers on the test

Versions
npmPackages:
react: 19.0.0 => 19.0.0
react-native: 0.79.1 => 0.79.1
react-test-renderer: 19.0.0 => 19.0.0
Metadata
Metadata
Assignees
Labels
No labels