Skip to content

Commit 3fe4f05

Browse files
committed
fix unit tests
1 parent b4d6628 commit 3fe4f05

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/ScrollTo.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component, createContext } from "react";
1+
import React, { Component, createContext, isValidElement } from "react";
22
import { findDOMNode } from "react-dom";
33
import { relative } from "./utilities/relative";
44

@@ -60,10 +60,12 @@ class ScrollTo extends Component {
6060
const top = ScrollTo._parseLocation(options.y, node, true);
6161
const left = ScrollTo._parseLocation(options.x, node, false);
6262

63-
const rNode = findDOMNode(node);
63+
if (isValidElement(node)) {
64+
const rNode = findDOMNode(node);
6465

65-
if (rNode) {
66-
node = rNode;
66+
if (rNode) {
67+
node = rNode;
68+
}
6769
}
6870

6971
if (node.scrollTo) {

src/tests/ScrollTo.spec.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { render, cleanup, fireEvent } from "react-testing-library";
33
import { shallow } from "enzyme";
44
import ScrollTo from "../ScrollTo";
55

6+
const { findDOMNode } = jest.requireMock("react-dom");
7+
68
afterEach(cleanup);
79

810
beforeEach(() => {

stories/ScrollByRef.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
import { Object } from "es6-shim";
32
import { ScrollStory } from ".";
43
import { ScrollTo } from "../src/index";
54

0 commit comments

Comments
 (0)