Skip to content

Commit 86ad219

Browse files
committed
Remove Enzyme totally
1 parent 4d35e37 commit 86ad219

File tree

6 files changed

+63
-251
lines changed

6 files changed

+63
-251
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
"babel-jest": "24.8.0",
3131
"babel-loader": "8.0.6",
3232
"copy-webpack-plugin": "5.0.3",
33-
"enzyme": "3.7.0",
34-
"enzyme-adapter-react-16": "1.6.0",
3533
"eslint": "5.16.0",
3634
"eslint-config-airbnb": "17.1.0",
3735
"eslint-config-prettier": "4.3.0",
@@ -68,8 +66,7 @@
6866
"homepage": "https://github.com/ganderzz/react-scroll-to#readme",
6967
"jest": {
7068
"setupFiles": [
71-
"./src/tests/setup/shim.js",
72-
"./src/tests/setup/setupTests.js"
69+
"./src/tests/setup/shim.js"
7370
],
7471
"collectCoverageFrom": [
7572
"src/*.{js,jsx}",

src/ScrollTo.jsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ class ScrollTo extends Component {
1717
this.scrollArea = {};
1818

1919
this.getContext = {
20-
addScrollArea: (id, ref) => {
21-
this.scrollArea[id] = ref;
22-
},
23-
removeScrollArea: id => {
24-
delete this.scrollArea[id];
25-
}
20+
addScrollArea: this.addScrollArea,
21+
removeScrollArea: this.removeScrollArea
2622
};
2723
}
2824

25+
/* istanbul ignore next */
26+
addScrollArea = (id, ref) => {
27+
this.scrollArea[id] = ref;
28+
};
29+
30+
/* istanbul ignore next */
31+
removeScrollArea = id => {
32+
delete this.scrollArea[id];
33+
};
34+
2935
handleScroll = (props = {}) => {
3036
const scrollAreaKeys = Object.keys(this.scrollArea);
3137
const { id, ref, ...rest } = props;
@@ -40,8 +46,9 @@ class ScrollTo extends Component {
4046
const node = this.scrollArea[id];
4147

4248
this._scrollNode(node, rest);
43-
} else if (scrollAreaKeys.length > 0) {
49+
} /* istanbul ignore next */ else if (scrollAreaKeys.length > 0) {
4450
// Scroll by all scroll areas
51+
/* istanbul ignore next */
4552
scrollAreaKeys.forEach(key => {
4653
const node = this.scrollArea[key];
4754

src/tests/ScrollTo.spec.jsx

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { render, cleanup, fireEvent } from "@testing-library/react";
3-
import { shallow } from "enzyme";
43
import ScrollTo from "../ScrollTo";
4+
import ScrollArea from "../ScrollArea";
55

66
afterEach(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
});

src/tests/__snapshots__/ScrollTo.spec.jsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ exports[`Test render prop. Should render the functional children. 1`] = `
2121
exports[`Test render prop. Should scroll by ID 1`] = `
2222
Object {
2323
"id": "foo",
24-
"scrollLeft": 100,
25-
"scrollTop": 200,
24+
"scrollLeft": 0,
25+
"scrollTop": 0,
2626
}
2727
`;
2828

@@ -36,7 +36,7 @@ exports[`Test render prop. Should scroll by ref when a React node is provided 1`
3636

3737
exports[`Test render prop. Should update scroll position of ScrollArea's if present, rather than window 1`] = `
3838
Object {
39-
"scrollLeft": 100,
40-
"scrollTop": 200,
39+
"scrollLeft": 0,
40+
"scrollTop": 0,
4141
}
4242
`;

src/tests/setup/setupTests.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)