mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
Some older React versions have different module import names and are missing certain features. This PR mocks modules that don't exist and maps modules in older versions to the ones that are required in tests. Specifically: * In React v16.5, scheduler is named schedule * In pre concurrent React, there is no act * Prior to React v18.0, react-dom/client doesn't exist * In DevTools, we expect to use scheduler/tracing-profiling instead of scheduler/tracing
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// Regression tests use a React DOM profiling, so we need
|
|
// to replace these tests with scheduler/tracing-profiling
|
|
jest.mock('scheduler/tracing', () => {
|
|
return jest.requireActual('scheduler/tracing-profiling');
|
|
});
|
|
|
|
// act doesn't exist in older versions of React, but
|
|
// DevTools tests sometimes import and depend on act to run.
|
|
// If act doesn't exist for a particular version of React, we will
|
|
// mock it with a function. This should work in most tests
|
|
// that we want to call with older versions of React.
|
|
// TODO (luna) Refactor act in DevTools test utils to not depend
|
|
// on act in react-dom or react-test-renderer so we don't need to do this
|
|
jest.mock('react-test-renderer', () => {
|
|
const reactTestRenderer = jest.requireActual('react-test-renderer');
|
|
if (!reactTestRenderer.act) {
|
|
reactTestRenderer.act = fn => fn();
|
|
}
|
|
return reactTestRenderer;
|
|
});
|
|
|
|
jest.mock('react-dom/test-utils', () => {
|
|
const testUtils = jest.requireActual('react-dom/test-utils');
|
|
if (!testUtils.act) {
|
|
testUtils.act = fn => fn();
|
|
}
|
|
return testUtils;
|
|
});
|