Skip to content

Minimal example showing issue with runWithRealTimers and setimmediate shim #1768

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
preset: 'react-native',
setupFilesAfterEnv: ['./jest-setup.ts'],
testEnvironment: "jsdom", // This causes setImmediate to be undefined.
testPathIgnorePatterns: ['build/', 'examples/', 'experiments-app/', 'timer-utils'],
testTimeout: 60000,
transformIgnorePatterns: ['/node_modules/(?!(@react-native|react-native)/).*/'],
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@
"eslint-plugin-simple-import-sort": "^12.1.1",
"flow-bin": "~0.170.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^2.8.8",
"react": "19.0.0",
"react-native": "0.79.1",
13 changes: 13 additions & 0 deletions src/__tests__/runWithRealTimers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { setImmediate, setTimeout } from '../helpers/timers';

describe('runWithRealTimers', () => {
test('real setImmediate is called when timers are fake', async () => {
jest.useFakeTimers({ legacyFakeTimers: false });
const timeout = new Promise((_, reject) => setTimeout(reject, 1000))
const immediate = new Promise(resolve => setImmediate(resolve))
const result = await Promise.race([timeout, immediate])
.then(() => 'resolve')
.catch(() => 'reject')
expect(result).toEqual('resolve')
});
});
Loading