11import React from "react" ;
22import { render , cleanup , fireEvent } from "@testing-library/react" ;
3- import { shallow } from "enzyme" ;
43import ScrollTo from "../ScrollTo" ;
4+ import ScrollArea from "../ScrollArea" ;
55
66afterEach ( cleanup ) ;
77
@@ -63,32 +63,35 @@ describe("Test render prop.", () => {
6363 } ) ;
6464
6565 it ( "Should remove scroll area." , ( ) => {
66- const wrapper = shallow ( < ScrollTo > { ( ) => < div > Test</ div > } </ ScrollTo > ) ;
67- const childContext = wrapper . instance ( ) . getContext ;
68- childContext . addScrollArea ( "id" , "foo" ) ;
66+ let element = new ScrollTo ( ) ;
67+ element . addScrollArea ( "id" , "foo" ) ;
6968
70- childContext . removeScrollArea ( "id" ) ;
69+ element . removeScrollArea ( "id" ) ;
7170
72- expect ( wrapper . instance ( ) . scrollArea ) . toEqual ( { } ) ;
71+ expect ( element . scrollArea ) . toEqual ( { } ) ;
7372 } ) ;
7473
7574 it ( "Should update scroll position of ScrollArea's if present, rather than window" , ( ) => {
7675 const mockNode = {
7776 scrollLeft : 0 ,
7877 scrollTop : 0
7978 } ;
80- const wrapper = shallow (
79+ const { container } = render (
8180 < ScrollTo >
8281 { ( { scrollTo } ) => (
83- < button onClick = { ( ) => scrollTo ( { x : 100 , y : 200 } ) } > test</ button >
82+ < React . Fragment >
83+ < button onClick = { ( ) => scrollTo ( { id : "id" , x : 100 , y : 200 } ) } >
84+ test
85+ </ button >
86+
87+ < ScrollArea id = "id" > test</ ScrollArea >
88+ </ React . Fragment >
8489 ) }
8590 </ ScrollTo >
8691 ) ;
87- const childContext = wrapper . instance ( ) . getContext ;
88- childContext . addScrollArea ( "id" , mockNode ) ;
8992
90- const buttonEl = wrapper . find ( "button" ) ;
91- buttonEl . simulate ( " click" ) ;
93+ const buttonEl = container . querySelector ( "button" ) ;
94+ fireEvent . click ( buttonEl ) ;
9295
9396 expect ( mockNode ) . toMatchSnapshot ( ) ;
9497 } ) ;
@@ -99,23 +102,22 @@ describe("Test render prop.", () => {
99102 scrollTop : 0 ,
100103 id : "foo"
101104 } ;
102- const wrapper = shallow (
105+ const { container } = render (
103106 < ScrollTo >
104107 { ( { scrollTo } ) => (
105- < button
106- type = "button"
107- onClick = { ( ) => scrollTo ( { id : "foo" , x : 100 , y : 200 } ) }
108- >
109- test
110- </ button >
108+ < React . Fragment >
109+ < button onClick = { ( ) => scrollTo ( { id : "foo" , x : 100 , y : 200 } ) } >
110+ test
111+ </ button >
112+
113+ < ScrollArea id = "foo" > test</ ScrollArea >
114+ </ React . Fragment >
111115 ) }
112116 </ ScrollTo >
113117 ) ;
114- const childContext = wrapper . instance ( ) . getContext ;
115- childContext . addScrollArea ( "foo" , mockNode ) ;
116118
117- const buttonEl = wrapper . find ( "button" ) ;
118- buttonEl . simulate ( " click" ) ;
119+ const buttonEl = container . querySelector ( "button" ) ;
120+ fireEvent . click ( buttonEl ) ;
119121
120122 expect ( mockNode ) . toMatchSnapshot ( ) ;
121123 } ) ;
@@ -126,23 +128,24 @@ describe("Test render prop.", () => {
126128 scrollTop : 0 ,
127129 id : "foo"
128130 } ;
129- const wrapper = shallow (
131+ const { container } = render (
130132 < ScrollTo >
131133 { ( { scrollTo } ) => (
132- < button
133- type = "button"
134- onClick = { ( ) => scrollTo ( { id : "unknown-id" , x : 100 , y : 200 } ) }
135- >
136- test
137- </ button >
134+ < React . Fragment >
135+ < button
136+ onClick = { ( ) => scrollTo ( { id : "UnKnOWN-id" , x : 100 , y : 200 } ) }
137+ >
138+ test
139+ </ button >
140+
141+ < ScrollArea id = "foo" > test</ ScrollArea >
142+ </ React . Fragment >
138143 ) }
139144 </ ScrollTo >
140145 ) ;
141- const childContext = wrapper . instance ( ) . getContext ;
142- childContext . addScrollArea ( "foo" , mockNode ) ;
143146
144- const buttonEl = wrapper . find ( "button" ) ;
145- buttonEl . simulate ( " click" ) ;
147+ const buttonEl = container . querySelector ( "button" ) ;
148+ fireEvent . click ( buttonEl ) ;
146149
147150 expect ( mockNode ) . toMatchSnapshot ( ) ;
148151 } ) ;
0 commit comments