11import React from "react" ;
22import { render , cleanup , fireEvent } from "react-testing-library" ;
33import { shallow } from "enzyme" ;
4- import ScrollTo from "../ScrollTo" ;
54import createReactContext from "create-react-context" ;
6-
7- const { findDOMNode } = jest . requireMock ( "react-dom" ) ;
5+ import ScrollTo from "../ScrollTo" ;
86
97afterEach ( cleanup ) ;
108
@@ -177,7 +175,7 @@ describe("Test render prop.", () => {
177175 ] ) ;
178176 } ) ;
179177
180- it ( "Should scroll by ref when provided" , ( ) => {
178+ it ( "Should scroll by ref when a DOM node is provided" , ( ) => {
181179 const refDOM = React . createRef ? React . createRef ( ) : createReactContext ( ) ;
182180 const { getByText } = render (
183181 < ScrollTo >
@@ -202,6 +200,34 @@ describe("Test render prop.", () => {
202200 expect ( refDOM . current ) . toMatchSnapshot ( ) ;
203201 } ) ;
204202
203+ it ( "Should scroll by ref when a React node is provided" , ( ) => {
204+ const refDOM = { } ;
205+ const MyElement = ( { children, ...props } ) => (
206+ < div { ...props } > { children } </ div >
207+ ) ;
208+
209+ const { getByText } = render (
210+ < ScrollTo >
211+ { ( { scrollTo } ) => (
212+ < >
213+ < MyElement
214+ onClick = { ( ) => scrollTo ( { ref : refDOM , x : 100 , y : 200 } ) }
215+ >
216+ myBtn
217+ </ MyElement >
218+
219+ < div ref = { ( ) => { } } > test</ div >
220+ </ >
221+ ) }
222+ </ ScrollTo >
223+ ) ;
224+
225+ const buttonEl = getByText ( "myBtn" ) ;
226+ fireEvent . click ( buttonEl ) ;
227+
228+ expect ( refDOM . current ) . toMatchSnapshot ( ) ;
229+ } ) ;
230+
205231 it ( "Should handle invalid ref" , ( ) => {
206232 const refDOM = { } ;
207233 const { getByText } = render (
@@ -230,7 +256,7 @@ describe("Test render prop.", () => {
230256
231257 it ( "Should handle using the relative() function" , ( ) => {
232258 const refDOM = React . createRef ? React . createRef ( ) : createReactContext ( ) ;
233- const { getByText, baseElement } = render (
259+ const { getByText } = render (
234260 < ScrollTo >
235261 { ( { scrollTo, relative } ) => (
236262 < >
0 commit comments