Skip to content

Commit 45633eb

Browse files
committed
use React 18 render
1 parent 7e9ac3e commit 45633eb

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

__tests__/api/meta.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ describe('meta tags', () => {
266266
it('fails gracefully when meta is wrong shape', () => {
267267
const originalConsole = global.console;
268268
global.console.warn = vi.fn();
269-
global.console.error = vi.fn();
270269

271270
render(
272271
<Helmet
@@ -282,7 +281,6 @@ describe('meta tags', () => {
282281

283282
expect(existingTags).toHaveLength(0);
284283

285-
expect(console.error).toHaveBeenCalled();
286284
expect(console.warn).toHaveBeenCalled();
287285

288286
expect((console.warn as MockedFunction<any>).mock.calls[0][0]).toMatchSnapshot();

__tests__/setup-test-env.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import '@testing-library/jest-dom';
2-
import ReactDOM from 'react-dom';
32

43
import { clearInstances } from '../src/HelmetData';
54

5+
import { unmount } from './utils';
6+
7+
// @ts-ignore
8+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
9+
610
let headElement: HTMLHeadElement;
711

812
beforeEach(() => {
@@ -13,10 +17,7 @@ beforeEach(() => {
1317
});
1418

1519
afterEach(() => {
16-
const mount = document.getElementById('mount');
17-
if (mount) {
18-
ReactDOM.unmountComponentAtNode(mount);
19-
}
20+
unmount();
2021

2122
clearInstances();
2223
});

__tests__/utils.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
import type { ReactNode } from 'react';
22
import React, { StrictMode } from 'react';
3-
import ReactDOM from 'react-dom';
3+
import { createRoot } from 'react-dom/client';
4+
import type { Root } from 'react-dom/client';
5+
import { act } from 'react-dom/test-utils';
46

57
import Provider from '../src/Provider';
68

9+
let root: Root | null = null;
10+
11+
export const unmount = () => {
12+
act(() => {
13+
root?.unmount();
14+
root = null;
15+
});
16+
};
17+
718
export const render = (node: ReactNode, context = {} as any) => {
8-
ReactDOM.render(
9-
<StrictMode>
10-
<Provider context={context}>{node}</Provider>
11-
</StrictMode>,
12-
document.getElementById('mount')
13-
);
19+
if (!root) {
20+
const elem = document.getElementById('mount') as HTMLElement;
21+
root = createRoot(elem);
22+
}
23+
24+
act(() => {
25+
root?.render(
26+
<StrictMode>
27+
<Provider context={context}>{node}</Provider>
28+
</StrictMode>
29+
);
30+
});
1431
};
1532

1633
export const renderContext = (node: ReactNode) => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy