Skip to content

Commit 7e468bb

Browse files
committed
chore(jest): update tests to react 16 and enzyme 3
1 parent 1a50cb0 commit 7e468bb

File tree

7 files changed

+189
-116
lines changed

7 files changed

+189
-116
lines changed

jest.setup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var Enzyme = require("enzyme");
2+
var Adapter = require("enzyme-adapter-react-16");
3+
4+
Enzyme.configure({ adapter: new Adapter() });

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"peerDependencies": {
4747
"prop-types": "^15.5.8",
48-
"react": "^15.0.0 || ^16.0.0-alpha || 16.0.0-rc.2"
48+
"react": "^15.0.0 || ^16.0.0"
4949
},
5050
"devDependencies": {
5151
"@types/classnames": "0.0.31",
@@ -62,13 +62,14 @@
6262
"chalk": "^2.0.1",
6363
"conventional-changelog-cli": "1.1.1",
6464
"cross-env": "^4.0.0",
65-
"enzyme": "^2.8.2",
65+
"enzyme": "^3.2.0",
66+
"enzyme-adapter-react-16": "^1.1.0",
6667
"glob": "^7.1.2",
6768
"jest": "^20.0.3",
6869
"prettier": "^1.5.2",
6970
"prop-types": "^15.5.10",
70-
"react": "15.6.1",
71-
"react-dom": "15.6.1",
71+
"react": "16.1.1",
72+
"react-dom": "16.1.1",
7273
"react-test-renderer": "^15.3.1",
7374
"readline-sync": "^1.4.7",
7475
"replace-in-file": "^2.0.3",
@@ -86,6 +87,7 @@
8687
"webpack-dev-server": "^2.8.1"
8788
},
8889
"jest": {
90+
"setupFiles": ["../jest.setup.js"],
8991
"rootDir": "src",
9092
"transform": {
9193
".(ts|tsx)": "<rootDir>/../node_modules/ts-jest/preprocessor.js"
@@ -104,4 +106,4 @@
104106
}
105107
}
106108
}
107-
}
109+
}

src/components/__tests__/UIRouter.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('<UIRouter>', () => {
3838
<Child />
3939
</UIRouter>,
4040
);
41-
expect(wrapper.find(Child).node.context.router).toBeDefined();
41+
expect(wrapper.find(Child).instance().context.router).toBeDefined();
4242
});
4343

4444
it('accepts an instance via prop', () => {
@@ -50,6 +50,6 @@ describe('<UIRouter>', () => {
5050
<Child />
5151
</UIRouter>,
5252
);
53-
expect(wrapper.find(Child).node.context.router.__TEST__).toBe(true);
53+
expect(wrapper.find(Child).instance().context.router.__TEST__).toBe(true);
5454
});
5555
});

src/components/__tests__/UISref.test.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('<UISref>', () => {
4747
</UIRouter>,
4848
);
4949
return router.stateService.go('state').then(() => {
50+
wrapper.update();
5051
const props = wrapper.find('a').props();
5152
expect(typeof props.onClick).toBe('function');
5253
expect(props.href.includes('/state2')).toBe(true);
@@ -63,12 +64,14 @@ describe('<UISref>', () => {
6364
return router.stateService
6465
.go('state')
6566
.then(() => {
66-
const uiSref = wrapper.find(UISref).nodes[0];
67+
wrapper.update();
68+
const uiSref = wrapper.find(UISref).at(0);
6769
expect(wrapper.html()).toBe('<a href="/state2" class="">state2</a>');
68-
spy = sinon.spy(uiSref, 'deregister');
70+
spy = sinon.spy(uiSref.instance(), 'deregister');
6971
return router.stateService.go('state2');
7072
})
7173
.then(() => {
74+
wrapper.update();
7275
expect(spy.calledOnce).toBe(true);
7376
});
7477
});
@@ -86,6 +89,7 @@ describe('<UISref>', () => {
8689
</UIRouter>,
8790
);
8891
return router.stateService.go('state').then(() => {
92+
wrapper.update();
8993
const link = wrapper.find('a');
9094
const props = link.props();
9195
expect(typeof props.onClick).toBe('function');
@@ -103,7 +107,8 @@ describe('<UISref>', () => {
103107
</UIRouter>,
104108
);
105109
return router.stateService.go('state').then(() => {
106-
let stub = sinon.stub(wrapper.node.router.stateService, 'go');
110+
wrapper.update();
111+
let stub = sinon.stub(wrapper.instance().router.stateService, 'go');
107112
const link = wrapper.find('a');
108113
link.simulate('click');
109114
link.simulate('click', {button: 1});
@@ -122,8 +127,8 @@ describe('<UISref>', () => {
122127
</UIRouter>,
123128
);
124129
expect(
125-
wrapper.find(UISref).node.context.parentUIViewAddress,
130+
wrapper.find(UISref).instance().context.parentUIViewAddress,
126131
).toBeUndefined();
127-
expect(wrapper.find(UISref).node.getOptions().relative.name).toBe('');
132+
expect(wrapper.find(UISref).instance().getOptions().relative.name).toBe('');
128133
});
129134
});

src/components/__tests__/UISrefActive.test.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe('<UISrefActive>', () => {
107107
</UIRouter>,
108108
);
109109
return router.stateService.go('simple').then(() => {
110+
wrapper.update();
110111
const props = wrapper.find('a').props();
111112
expect(typeof props.onClick).toBe('function');
112113
expect(props.href.includes('/child1')).toBe(true);
@@ -122,12 +123,14 @@ describe('<UISrefActive>', () => {
122123
return router.stateService
123124
.go('parent.child1')
124125
.then(() => {
126+
wrapper.update();
125127
const activeLink = wrapper.find('a.active');
126128
expect(activeLink.length).toBe(1);
127129
expect(activeLink.props().href.includes('/child1')).toBe(true);
128130
return router.stateService.go('parent.child2');
129131
})
130132
.then(() => {
133+
wrapper.update();
131134
const activeLink = wrapper.find('a.active');
132135
expect(activeLink.length).toBe(1);
133136
expect(activeLink.props().href.includes('/child2')).toBe(true);
@@ -145,6 +148,7 @@ describe('<UISrefActive>', () => {
145148
</UIRouter>,
146149
);
147150
return router.stateService.go('throw').then(() => {
151+
wrapper.update();
148152
expect(spy.called).toBe(true);
149153
});
150154
});
@@ -159,11 +163,13 @@ describe('<UISrefActive>', () => {
159163
return router.stateService
160164
.go('simple')
161165
.then(() => {
162-
node = wrapper.find(UISrefActive).get(0);
163-
spy = sinon.spy(node, 'deregister');
166+
wrapper.update();
167+
node = wrapper.find(UISrefActive).at(0);
168+
spy = sinon.spy(node.instance(), 'deregister');
164169
return router.stateService.go('simple2');
165170
})
166171
.then(() => {
172+
wrapper.update();
167173
expect(spy.called).toBe(true);
168174
});
169175
});
@@ -184,11 +190,13 @@ describe('<UISrefActive>', () => {
184190
return router.stateService
185191
.go('withParams', {param: 5})
186192
.then(() => {
193+
wrapper.update();
187194
const activeLink = wrapper.find('a.active');
188195
expect(activeLink.length).toBe(1);
189196
return router.stateService.go('withParams', {param: 3});
190197
})
191198
.then(() => {
199+
wrapper.update();
192200
const activeLink = wrapper.find('a.active');
193201
expect(activeLink.length).toBe(0);
194202
});
@@ -204,9 +212,9 @@ describe('<UISrefActive>', () => {
204212
</UISrefActive>
205213
</UIRouter>,
206214
);
207-
let node = wrapper.find(UISrefActive).node;
208-
expect(node.context.parentUIViewAddress).toBeUndefined();
209-
expect(node.states[0].state.name).toBe('parent.child1');
215+
let node = wrapper.find(UISrefActive).at(0);
216+
expect(node.instance().context.parentUIViewAddress).toBeUndefined();
217+
expect(node.instance().states[0].state.name).toBe('parent.child1');
210218
});
211219

212220
it('works with multiple <UISref> children', () => {
@@ -227,9 +235,9 @@ describe('<UISrefActive>', () => {
227235
</UISrefActive>
228236
</UIRouter>,
229237
);
230-
let node = wrapper.find(UISrefActive).node;
231-
expect(node.context.parentUIViewAddress).toBeUndefined();
232-
expect(node.states.length).toBe(3);
238+
const node = wrapper.find(UISrefActive).at(0);
239+
expect(node.instance().context.parentUIViewAddress).toBeUndefined();
240+
expect(node.instance().states.length).toBe(3);
233241
});
234242

235243
it("removes active state of UISref when it's unmounted", () => {
@@ -244,10 +252,10 @@ describe('<UISrefActive>', () => {
244252
</UISrefActive>
245253
</UIRouter>;
246254
const wrapper = mount(<Comp show={true} />);
247-
const node = wrapper.find(UISrefActive).get(0);
248-
expect(node.states.length).toBe(1);
255+
const node = wrapper.find(UISrefActive).at(0);
256+
expect(node.instance().states.length).toBe(1);
249257
wrapper.setProps({show: false});
250-
expect(node.states.length).toBe(0);
258+
expect(node.instance().states.length).toBe(0);
251259
});
252260

253261
it('checks for exact state match when exact prop is provided', () => {
@@ -279,10 +287,12 @@ describe('<UISrefActive>', () => {
279287
return router.stateService
280288
.go('_parent._child')
281289
.then(() => {
290+
wrapper.update();
282291
expect(wrapper.find('a.active').length).toBe(1);
283292
return router.stateService.go('_parent');
284293
})
285294
.then(() => {
295+
wrapper.update();
286296
expect(wrapper.find('a.active').length).toBe(2);
287297
});
288298
});

src/components/__tests__/UIView.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ describe('<UIView>', () => {
128128
</UIRouter>,
129129
);
130130
return router.stateService.go('__state').then(() => {
131+
wrapper.update();
131132
expect(wrapper.find(Comp).props().resolves).not.toBeUndefined();
132133
expect(wrapper.find(Comp).props().transition).not.toBeUndefined();
133134
});
@@ -147,6 +148,7 @@ describe('<UIView>', () => {
147148
</UIRouter>,
148149
);
149150
return router.stateService.go('__state').then(() => {
151+
wrapper.update();
150152
expect(wrapper.find(Comp).props().resolves.foo).toBe('bar');
151153
});
152154
});
@@ -256,7 +258,7 @@ describe('<UIView>', () => {
256258
{props.show ? <UIView /> : <div />}
257259
</UIRouter>;
258260
const wrapper = mount(<Component show={true} />);
259-
let stub = sinon.stub(wrapper.find(UIView).get(0), 'deregister');
261+
let stub = sinon.stub(wrapper.find(UIView).at(0).instance(), 'deregister');
260262
wrapper.setProps({show: false});
261263
expect(stub.calledOnce).toBe(true);
262264
});

0 commit comments

Comments
 (0)