Skip to content

Commit 858af7c

Browse files
committed
chore(test): Update enzyme to 3.1.0
1 parent 4ebb8ed commit 858af7c

File tree

3 files changed

+169
-118
lines changed

3 files changed

+169
-118
lines changed

package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@
3030
"bugs": {
3131
"url": "https://github.com/reactjs/react-tabs/issues"
3232
},
33-
"files": ["dist", "lib", "style"],
33+
"files": [
34+
"dist",
35+
"lib",
36+
"style"
37+
],
3438
"homepage": "https://github.com/reactjs/react-tabs",
35-
"keywords": ["react", "tabs", "a11y", "react-component"],
39+
"keywords": [
40+
"react",
41+
"tabs",
42+
"a11y",
43+
"react-component"
44+
],
3645
"peerDependencies": {
3746
"react": "^0.14.9 || ^15.3.0"
3847
},
@@ -50,7 +59,8 @@
5059
"conventional-github-releaser": "^1.1.12",
5160
"cross-env": "^5.0.0",
5261
"css-loader": "^0.28.0",
53-
"enzyme": "^2.3.0",
62+
"enzyme": "^3.1.0",
63+
"enzyme-adapter-react-15": "^1.0.1",
5464
"eslint": "^4.5.0",
5565
"eslint-config-airbnb": "^15.0.1",
5666
"eslint-plugin-import": "^2.2.0",
@@ -80,10 +90,15 @@
8090
"prop-types": "^15.5.0"
8191
},
8292
"jest": {
83-
"roots": ["src"],
93+
"roots": [
94+
"src"
95+
],
8496
"testRegex": "/__tests__/.+-test\\.js$"
8597
},
8698
"lint-staged": {
87-
"src/**/*.js": ["eslint --fix", "git add"]
99+
"src/**/*.js": [
100+
"eslint --fix",
101+
"git add"
102+
]
88103
}
89104
}

src/components/__tests__/Tabs-test.js

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-env jest */
22
/* eslint-disable react/no-multi-comp */
33
import React from 'react';
4-
import { shallow, mount } from 'enzyme';
4+
import Enzyme, { shallow, mount } from 'enzyme';
5+
import Adapter from 'enzyme-adapter-react-15';
56
import renderer from 'react-test-renderer';
67
import Tab from '../Tab';
78
import TabList from '../TabList';
@@ -10,6 +11,8 @@ import Tabs from '../Tabs';
1011
import { reset as resetIdCounter } from '../../helpers/uuid';
1112
import { TabListWrapper, TabWrapper, TabPanelWrapper } from './helpers/higherOrder';
1213

14+
Enzyme.configure({ adapter: new Adapter() });
15+
1316
function expectToMatchSnapshot(component) {
1417
expect(renderer.create(component).toJSON()).toMatchSnapshot();
1518
}
@@ -34,8 +37,8 @@ function createTabs(props = {}) {
3437
}
3538

3639
function assertTabSelected(wrapper, index) {
37-
const tab = wrapper.childAt(0).childAt(index);
38-
const panel = wrapper.childAt(index + 1);
40+
const tab = wrapper.find(Tab).at(index);
41+
const panel = wrapper.find(TabPanel).at(index);
3942

4043
expect(tab.prop('selected')).toBe(true);
4144
expect(panel.prop('selected')).toBe(true);
@@ -76,8 +79,8 @@ describe('<Tabs />', () => {
7679
);
7780

7881
wrapper
79-
.childAt(0)
80-
.childAt(1)
82+
.find(Tab)
83+
.at(1)
8184
.simulate('click');
8285

8386
expect(called.index).toBe(1);
@@ -103,60 +106,61 @@ describe('<Tabs />', () => {
103106
test('should update selectedIndex when clicked', () => {
104107
const wrapper = mount(createTabs());
105108
wrapper
106-
.childAt(0)
107-
.childAt(1)
109+
.find(Tab)
110+
.at(1)
108111
.simulate('click');
109112

110113
assertTabSelected(wrapper, 1);
111114
});
112115

113116
test('should update selectedIndex when tab child is clicked', () => {
114117
const wrapper = mount(createTabs());
115-
const tablist = wrapper.childAt(0);
116-
tablist
117-
.childAt(2)
118-
.first()
118+
wrapper
119+
.find(Tab)
120+
.at(2)
121+
.childAt(0)
119122
.simulate('click');
120123

121124
assertTabSelected(wrapper, 2);
122125
});
123126

124127
test('should not change selectedIndex when clicking a disabled tab', () => {
125128
const wrapper = mount(createTabs({ defaultIndex: 0 }));
126-
127129
wrapper
128-
.childAt(0)
129-
.childAt(3)
130+
.find(Tab)
131+
.at(3)
130132
.simulate('click');
133+
131134
assertTabSelected(wrapper, 0);
132135
});
133136
});
134137

135138
describe('performance', () => {
136139
test('should only render the selected tab panel', () => {
137140
const wrapper = mount(createTabs());
141+
const tabPanels = wrapper.find(TabPanel);
138142

139-
expect(wrapper.childAt(1).text()).toBe('Hello Foo');
140-
expect(wrapper.childAt(2).text()).toBe('');
141-
expect(wrapper.childAt(3).text()).toBe('');
143+
expect(tabPanels.at(0).text()).toBe('Hello Foo');
144+
expect(tabPanels.at(1).text()).toBe('');
145+
expect(tabPanels.at(2).text()).toBe('');
142146

143147
wrapper
144-
.childAt(0)
145-
.childAt(1)
148+
.find(Tab)
149+
.at(1)
146150
.simulate('click');
147151

148-
expect(wrapper.childAt(1).text()).toBe('');
149-
expect(wrapper.childAt(2).text()).toBe('Hello Bar');
150-
expect(wrapper.childAt(3).text()).toBe('');
152+
expect(tabPanels.at(0).text()).toBe('');
153+
expect(tabPanels.at(1).text()).toBe('Hello Bar');
154+
expect(tabPanels.at(2).text()).toBe('');
151155

152156
wrapper
153-
.childAt(0)
154-
.childAt(2)
157+
.find(Tab)
158+
.at(2)
155159
.simulate('click');
156160

157-
expect(wrapper.childAt(1).text()).toBe('');
158-
expect(wrapper.childAt(2).text()).toBe('');
159-
expect(wrapper.childAt(3).text()).toBe('Hello Baz');
161+
expect(tabPanels.at(0).text()).toBe('');
162+
expect(tabPanels.at(1).text()).toBe('');
163+
expect(tabPanels.at(2).text()).toBe('Hello Baz');
160164
});
161165

162166
test('should render all tabs if forceRenderTabPanel is true', () => {
@@ -363,15 +367,14 @@ describe('<Tabs />', () => {
363367
</Tabs>,
364368
);
365369

366-
const innerTabs = wrapper.childAt(1).childAt(0);
367-
368-
innerTabs
369-
.childAt(0)
370-
.childAt(1)
370+
wrapper
371+
.find('Tabs.second')
372+
.find(Tab)
373+
.at(1)
371374
.simulate('click');
372375

373376
assertTabSelected(wrapper, 0);
374-
assertTabSelected(innerTabs, 1);
377+
assertTabSelected(wrapper.find('Tabs.second'), 1);
375378
});
376379

377380
test('should allow other DOM nodes', () => {
@@ -410,14 +413,14 @@ describe('<Tabs />', () => {
410413
assertTabSelected(wrapper, 0);
411414

412415
wrapper
413-
.childAt(0)
414-
.childAt(1)
416+
.find(Tab)
417+
.at(1)
415418
.simulate('click');
416419
assertTabSelected(wrapper, 0);
417420

418421
wrapper
419-
.childAt(0)
420-
.childAt(2)
422+
.find(Tab)
423+
.at(2)
421424
.simulate('click');
422425
assertTabSelected(wrapper, 0);
423426
});
@@ -435,8 +438,8 @@ describe('<Tabs />', () => {
435438
assertTabSelected(wrapper, 0);
436439

437440
wrapper
438-
.childAt(0)
439-
.childAt(1)
441+
.find(Tab)
442+
.at(1)
440443
.simulate('click');
441444
assertTabSelected(wrapper, 1);
442445
expect(wasClicked).toBe(true);
@@ -455,8 +458,8 @@ describe('<Tabs />', () => {
455458
assertTabSelected(wrapper, 0);
456459

457460
wrapper
458-
.childAt(0)
459-
.childAt(0)
461+
.find(Tab)
462+
.at(0)
460463
.simulate('click');
461464
assertTabSelected(wrapper, 0);
462465
expect(wasClicked).toBe(true);
@@ -473,14 +476,14 @@ describe('<Tabs />', () => {
473476
const wrapper = mount(<Wrap />);
474477

475478
wrapper
476-
.childAt(0)
477-
.childAt(1)
479+
.find(Tab)
480+
.at(1)
478481
.simulate('click');
479482
assertTabSelected(wrapper, 1);
480483

481484
wrapper
482-
.childAt(0)
483-
.childAt(2)
485+
.find(Tab)
486+
.at(2)
484487
.simulate('click');
485488
assertTabSelected(wrapper, 2);
486489
});

0 commit comments

Comments
 (0)