File tree 3 files changed +30
-14
lines changed
3 files changed +30
-14
lines changed Original file line number Diff line number Diff line change @@ -266,7 +266,6 @@ describe('meta tags', () => {
266
266
it ( 'fails gracefully when meta is wrong shape' , ( ) => {
267
267
const originalConsole = global . console ;
268
268
global . console . warn = vi . fn ( ) ;
269
- global . console . error = vi . fn ( ) ;
270
269
271
270
render (
272
271
< Helmet
@@ -282,7 +281,6 @@ describe('meta tags', () => {
282
281
283
282
expect ( existingTags ) . toHaveLength ( 0 ) ;
284
283
285
- expect ( console . error ) . toHaveBeenCalled ( ) ;
286
284
expect ( console . warn ) . toHaveBeenCalled ( ) ;
287
285
288
286
expect ( ( console . warn as MockedFunction < any > ) . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
Original file line number Diff line number Diff line change 1
1
import '@testing-library/jest-dom' ;
2
- import ReactDOM from 'react-dom' ;
3
2
4
3
import { clearInstances } from '../src/HelmetData' ;
5
4
5
+ import { unmount } from './utils' ;
6
+
7
+ // @ts -ignore
8
+ globalThis . IS_REACT_ACT_ENVIRONMENT = true ;
9
+
6
10
let headElement : HTMLHeadElement ;
7
11
8
12
beforeEach ( ( ) => {
@@ -13,10 +17,7 @@ beforeEach(() => {
13
17
} ) ;
14
18
15
19
afterEach ( ( ) => {
16
- const mount = document . getElementById ( 'mount' ) ;
17
- if ( mount ) {
18
- ReactDOM . unmountComponentAtNode ( mount ) ;
19
- }
20
+ unmount ( ) ;
20
21
21
22
clearInstances ( ) ;
22
23
} ) ;
Original file line number Diff line number Diff line change 1
1
import type { ReactNode } from 'react' ;
2
2
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' ;
4
6
5
7
import Provider from '../src/Provider' ;
6
8
9
+ let root : Root | null = null ;
10
+
11
+ export const unmount = ( ) => {
12
+ act ( ( ) => {
13
+ root ?. unmount ( ) ;
14
+ root = null ;
15
+ } ) ;
16
+ } ;
17
+
7
18
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
+ } ) ;
14
31
} ;
15
32
16
33
export const renderContext = ( node : ReactNode ) => {
You can’t perform that action at this time.
0 commit comments