Skip to content

Commit 9ac270d

Browse files
test(dom-render): update react-dom mocks for version-aware tests
Co-Authored-By: gregorywong@box.com <gregorywong@box.com>
1 parent 8720c8c commit 9ac270d

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/utils/__tests__/dom-render.test.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@ import * as React from 'react';
22
import { versionAwareRender } from '../dom-render';
33

44
// Create mock functions with implementations
5-
const mockRender = jest.fn();
6-
const mockUnmountComponentAtNode = jest.fn();
7-
const mockRootRender = jest.fn();
8-
const mockRootUnmount = jest.fn();
9-
const mockCreateRoot = jest.fn(() => ({
5+
const mockRender = jest.fn().mockReturnValue(undefined);
6+
const mockUnmountComponentAtNode = jest.fn().mockReturnValue(true);
7+
const mockRootRender = jest.fn().mockReturnValue(undefined);
8+
const mockRootUnmount = jest.fn().mockReturnValue(undefined);
9+
const mockCreateRoot = jest.fn().mockReturnValue({
1010
render: mockRootRender,
1111
unmount: mockRootUnmount,
12-
}));
12+
});
1313

1414
// Mock modules before importing the module under test
15-
jest.mock('react-dom', () => ({
16-
__esModule: true,
17-
render: mockRender,
18-
unmountComponentAtNode: mockUnmountComponentAtNode,
19-
}));
20-
21-
jest.mock('react-dom/client', () => ({
22-
__esModule: true,
23-
createRoot: mockCreateRoot,
24-
}));
15+
jest.mock('react-dom', () => {
16+
const actual = jest.requireActual('react-dom');
17+
return {
18+
...actual,
19+
render: mockRender,
20+
unmountComponentAtNode: mockUnmountComponentAtNode,
21+
};
22+
});
23+
24+
jest.mock('react-dom/client', () => {
25+
const actual = jest.requireActual('react-dom/client');
26+
return {
27+
...actual,
28+
createRoot: mockCreateRoot,
29+
};
30+
});
2531

2632
describe('dom-render', () => {
2733
const TestComponent = () => <div>Test Component</div>;

0 commit comments

Comments
 (0)