You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yesterday we used the `react-addons-test-utils` library to write our first test against the `Timeline` component. However, this library is fairly low-level and can be a bit cumbersome to use. [Enzyme](http://airbnb.io/enzyme/) is a testing utility library released and maintained by the [AirBnb](http://airbnb.io) team and it offers a nicer, higher-level API for dealing with React components under test.
19
+
Yesterday we used the `react-dom/test-utils` library to write our first test against the `Timeline` component. However, this library is fairly low-level and can be a bit cumbersome to use. [Enzyme](http://airbnb.io/enzyme/) is a testing utility library released and maintained by the [AirBnb](http://airbnb.io) team and it offers a nicer, higher-level API for dealing with React components under test.
20
20
21
21
We're testing against our `<Timeline />` component:
22
22
@@ -30,7 +30,7 @@ Yesterday, we wrote our first test as the following:
30
30
31
31
```javascript
32
32
importReactfrom'react';
33
-
importTestUtilsfrom'react-addons-test-utils';
33
+
importTestUtilsfrom"react-dom/test-utils";
34
34
35
35
importTimelinefrom'../Timeline';
36
36
@@ -51,6 +51,16 @@ Rather than testing the complete component tree with Enzyme, we can test just th
51
51
52
52
Enzyme makes shallow rendering super easy. We'll use the `shallow` function exported by Enzyme to mount our component.
53
53
54
+
Let's first configure `enzyme` use the adapter that makes it compatible with React version 16. Create `src/setupTests.js` and add the following:
55
+
56
+
```javascript
57
+
import { configure } from"enzyme";
58
+
importAdapterfrom"enzyme-adapter-react-16";
59
+
60
+
configure({ adapter:newAdapter() });
61
+
62
+
```
63
+
54
64
Let's update the `src/components/Timeline/__tests__/Timeline-test.js` file to include the `shallow` function from `enzyme`:
55
65
56
66
```javascript
@@ -64,7 +74,7 @@ describe('Timeline', () => {
64
74
})
65
75
```
66
76
67
-
> Shallow rendering is supported by `react-addons-test-utils` as well. In fact, Enzyme just wraps this functionality. While we didn't use shallow rendering yesterday, if we were to use it would look like this:
77
+
> Shallow rendering is supported by `react-dom/test-utils` as well. In fact, Enzyme just wraps this functionality. While we didn't use shallow rendering yesterday, if we were to use it would look like this:
68
78
>
69
79
> ```javascript
70
80
>constrenderer=ReactTestUtils.createRenderer();
@@ -84,41 +94,11 @@ import Timeline from '../Timeline';
84
94
85
95
describe('Timeline', () => {
86
96
let wrapper;
87
-
88
-
it('wraps content in a div with .notificationsFrame class', () => {
97
+
98
+
it("wraps content in a div with .notificationsFrame class", () => {
0 commit comments