11/* global describe, it */
22
3- import React from 'react' ;
4- import ReactDOM from 'react-dom' ;
3+ import React , { act } from 'react' ;
4+ import { createRoot } from 'react-dom/client ' ;
55import { ParallaxController } from 'parallax-controller' ;
66
77import { render } from '@testing-library/react' ;
@@ -18,16 +18,15 @@ describe('A <ParallaxProvider>', () => {
1818 return < div /> ;
1919 } ;
2020
21- const render = ( ) => {
22- ReactDOM . render (
21+ const root = createRoot ( node ) ;
22+
23+ act ( ( ) => {
24+ root . render (
2325 < ParallaxProvider >
2426 < Child />
25- </ ParallaxProvider > ,
26- node
27+ </ ParallaxProvider >
2728 ) ;
28- } ;
29-
30- render ( ) ;
29+ } ) ;
3130
3231 expect ( child ) . toHaveBeenCalled ( ) ;
3332 } ) ;
@@ -155,32 +154,46 @@ describe('A <ParallaxProvider>', () => {
155154 const node1 = document . createElement ( 'div' ) ;
156155 const node2 = document . createElement ( 'div' ) ;
157156
158- const render = ( node : HTMLDivElement ) => {
159- let instance : ParallaxController | null = null ;
160- const GetInstance = ( ) => {
161- instance = useParallaxController ( ) ;
162- return null ;
163- } ;
164- ReactDOM . render (
165- // @ts -ignore
166- < ParallaxProvider >
167- < GetInstance />
168- </ ParallaxProvider > ,
169- node
170- ) ;
171- return instance ;
157+ // Use a different approach - capture instances after rendering
158+ let instance1 : ParallaxController | null = null ;
159+ let instance2 : ParallaxController | null = null ;
160+
161+ const GetInstance1 = ( ) => {
162+ instance1 = useParallaxController ( ) ;
163+ return null ;
164+ } ;
165+
166+ const GetInstance2 = ( ) => {
167+ instance2 = useParallaxController ( ) ;
168+ return null ;
172169 } ;
173170
174171 // first instance mounted
175- const instance1 = render ( node1 ) ;
172+ const root1 = createRoot ( node1 ) ;
173+ act ( ( ) => {
174+ root1 . render (
175+ // @ts -ignore
176+ < ParallaxProvider >
177+ < GetInstance1 />
178+ </ ParallaxProvider >
179+ ) ;
180+ } ) ;
176181 expect ( instance1 ) . toBeInstanceOf ( ParallaxController ) ;
177182
178183 // second instance mounted
179- const instance2 = render ( node2 ) ;
184+ const root2 = createRoot ( node2 ) ;
185+ act ( ( ) => {
186+ root2 . render (
187+ // @ts -ignore
188+ < ParallaxProvider >
189+ < GetInstance2 />
190+ </ ParallaxProvider >
191+ ) ;
192+ } ) ;
180193 expect ( instance2 ) . toBeInstanceOf ( ParallaxController ) ;
181194
182195 // unmount first instance
183- ReactDOM . unmountComponentAtNode ( node1 ) ;
196+ root1 . unmount ( ) ;
184197
185198 // this must still be defined
186199 expect ( instance2 ) . toBeInstanceOf ( ParallaxController ) ;
0 commit comments