Skip to content

Commit 00779b8

Browse files
committed
test: use Jest mocks instead of sinon
Jest mocks are an awesome feature, no need to use sinon.
1 parent 7235a10 commit 00779b8

File tree

3 files changed

+15
-97
lines changed

3 files changed

+15
-97
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"rollup-plugin-terser": "^4.0.2",
102102
"semantic-release": "^15.9.16",
103103
"semantic-release-alt-publish-dir": "^2.1.1",
104-
"sinon": "^6.3.4",
105104
"travis-deploy-once": "^5.0.8"
106105
},
107106
"release": {

test/Transition-test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33

44
import { mount } from 'enzyme'
5-
import sinon from 'sinon'
65

76
import Transition, {
87
UNMOUNTED,
@@ -90,13 +89,13 @@ describe('Transition', () => {
9089
})
9190

9291
it('should allow addEndListener instead of timeouts', done => {
93-
let listener = sinon.spy((node, end) => setTimeout(end, 0))
92+
let listener = jest.fn((node, end) => setTimeout(end, 0))
9493

9594
let inst = mount(
9695
<Transition
9796
addEndListener={listener}
9897
onEntered={() => {
99-
expect(listener.callCount).toEqual(1)
98+
expect(listener).toHaveBeenCalledTimes(1)
10099
done()
101100
}}
102101
>
@@ -214,8 +213,9 @@ describe('Transition', () => {
214213
})
215214

216215
it('should fire callbacks', done => {
217-
let onEnter = sinon.spy()
218-
let onEntering = sinon.spy()
216+
let callOrder = []
217+
let onEnter = jest.fn(() => callOrder.push('onEnter'))
218+
let onEntering = jest.fn(() => callOrder.push('onEntering'))
219219

220220
expect(wrapper.state('status')).toEqual(EXITED)
221221

@@ -227,9 +227,9 @@ describe('Transition', () => {
227227
onEntering,
228228

229229
onEntered() {
230-
expect(onEnter.calledOnce).toEqual(true)
231-
expect(onEntering.calledOnce).toEqual(true)
232-
expect(onEnter.calledBefore(onEntering)).toEqual(true)
230+
expect(onEnter).toHaveBeenCalledTimes(1)
231+
expect(onEntering).toHaveBeenCalledTimes(1)
232+
expect(callOrder).toEqual(['onEnter', 'onEntering'])
233233
done()
234234
},
235235
})
@@ -274,8 +274,9 @@ describe('Transition', () => {
274274
})
275275

276276
it('should fire callbacks', done => {
277-
let onExit = sinon.spy()
278-
let onExiting = sinon.spy()
277+
let callOrder = []
278+
let onExit = jest.fn(() => callOrder.push('onExit'))
279+
let onExiting = jest.fn(() => callOrder.push('onExiting'))
279280

280281
expect(wrapper.state('status')).toEqual(ENTERED)
281282

@@ -287,9 +288,9 @@ describe('Transition', () => {
287288
onExiting,
288289

289290
onExited() {
290-
expect(onExit.calledOnce).toEqual(true)
291-
expect(onExiting.calledOnce).toEqual(true)
292-
expect(onExit.calledBefore(onExiting)).toEqual(true)
291+
expect(onExit).toHaveBeenCalledTimes(1)
292+
expect(onExiting).toHaveBeenCalledTimes(1)
293+
expect(callOrder).toEqual(['onExit', 'onExiting'])
293294
done()
294295
},
295296
})

yarn.lock

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,30 +1437,6 @@
14371437
dependencies:
14381438
symbol-observable "^1.2.0"
14391439

1440-
"@sinonjs/commons@^1.0.2":
1441-
version "1.0.2"
1442-
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.0.2.tgz#3e0ac737781627b8844257fadc3d803997d0526e"
1443-
dependencies:
1444-
type-detect "4.0.8"
1445-
1446-
"@sinonjs/[email protected]", "@sinonjs/formatio@^3.0.0":
1447-
version "3.0.0"
1448-
resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-3.0.0.tgz#9d282d81030a03a03fa0c5ce31fd8786a4da311a"
1449-
dependencies:
1450-
"@sinonjs/samsam" "2.1.0"
1451-
1452-
"@sinonjs/[email protected]":
1453-
version "2.1.0"
1454-
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-2.1.0.tgz#b8b8f5b819605bd63601a6ede459156880f38ea3"
1455-
dependencies:
1456-
array-from "^2.1.1"
1457-
1458-
"@sinonjs/samsam@^2.1.1":
1459-
version "2.1.1"
1460-
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-2.1.1.tgz#f352621c24c9e9ab2ed293a7655e8d46bfd64c16"
1461-
dependencies:
1462-
array-from "^2.1.1"
1463-
14641440
"@storybook/addon-actions@^4.1.4":
14651441
version "4.1.4"
14661442
resolved "https://registry.yarnpkg.com/@storybook/addon-actions/-/addon-actions-4.1.4.tgz#d6ff166939b0f1b6c2de57c6716503449b17124d"
@@ -2312,10 +2288,6 @@ [email protected]:
23122288
version "1.1.1"
23132289
resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2"
23142290

2315-
array-from@^2.1.1:
2316-
version "2.1.1"
2317-
resolved "https://registry.yarnpkg.com/array-from/-/array-from-2.1.1.tgz#cfe9d8c26628b9dc5aecc62a9f5d8f1f352c1195"
2318-
23192291
array-ify@^1.0.0:
23202292
version "1.0.0"
23212293
resolved "https://registry.yarnpkg.com/array-ify/-/array-ify-1.0.0.tgz#9e528762b4a9066ad163a6962a364418e9626ece"
@@ -4337,7 +4309,7 @@ dezalgo@^1.0.0, dezalgo@~1.0.3:
43374309
asap "^2.0.0"
43384310
wrappy "1"
43394311

4340-
diff@^3.2.0, diff@^3.5.0:
4312+
diff@^3.2.0:
43414313
version "3.5.0"
43424314
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
43434315

@@ -7122,10 +7094,6 @@ jsx-ast-utils@^2.0.1:
71227094
dependencies:
71237095
array-includes "^3.0.3"
71247096

7125-
just-extend@^3.0.0:
7126-
version "3.0.0"
7127-
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-3.0.0.tgz#cee004031eaabf6406da03a7b84e4fe9d78ef288"
7128-
71297097
keycode@^2.2.0:
71307098
version "2.2.0"
71317099
resolved "http://storage.mds.yandex.net/get-npm/66641/keycode-2.2.0.tgz#3d0af56dc7b8b8e5cba8d0a97f107204eec22b04"
@@ -7386,10 +7354,6 @@ lodash.flattendeep@^4.4.0:
73867354
version "4.4.0"
73877355
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
73887356

7389-
lodash.get@^4.4.2:
7390-
version "4.4.2"
7391-
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
7392-
73937357
lodash.isarguments@^3.0.0:
73947358
version "3.1.0"
73957359
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
@@ -7458,14 +7422,6 @@ lodash@^4.17.11:
74587422
version "4.17.11"
74597423
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
74607424

7461-
lolex@^2.3.2:
7462-
version "2.7.0"
7463-
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.0.tgz#9c087a69ec440e39d3f796767cf1b2cdc43d5ea5"
7464-
7465-
lolex@^2.7.4:
7466-
version "2.7.5"
7467-
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.5.tgz#113001d56bfc7e02d56e36291cc5c413d1aa0733"
7468-
74697425
longest@^1.0.1:
74707426
version "1.0.1"
74717427
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
@@ -7974,16 +7930,6 @@ nice-try@^1.0.4:
79747930
version "1.0.4"
79757931
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.4.tgz#d93962f6c52f2c1558c0fbda6d512819f1efe1c4"
79767932

7977-
nise@^1.4.5:
7978-
version "1.4.5"
7979-
resolved "https://registry.yarnpkg.com/nise/-/nise-1.4.5.tgz#979a97a19c48d627bb53703726ae8d53ce8d4b3e"
7980-
dependencies:
7981-
"@sinonjs/formatio" "3.0.0"
7982-
just-extend "^3.0.0"
7983-
lolex "^2.3.2"
7984-
path-to-regexp "^1.7.0"
7985-
text-encoding "^0.6.4"
7986-
79877933
no-case@^2.2.0:
79887934
version "2.3.2"
79897935
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"
@@ -8863,12 +8809,6 @@ [email protected]:
88638809
version "0.1.7"
88648810
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
88658811

8866-
path-to-regexp@^1.7.0:
8867-
version "1.7.0"
8868-
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
8869-
dependencies:
8870-
isarray "0.0.1"
8871-
88728812
path-type@^1.0.0:
88738813
version "1.1.0"
88748814
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
@@ -10507,20 +10447,6 @@ signale@^1.2.1:
1050710447
figures "^2.0.0"
1050810448
pkg-conf "^2.1.0"
1050910449

10510-
sinon@^6.3.4:
10511-
version "6.3.4"
10512-
resolved "https://registry.yarnpkg.com/sinon/-/sinon-6.3.4.tgz#6f076d7ddcf381af6c16468ac83d30333a756ec8"
10513-
dependencies:
10514-
"@sinonjs/commons" "^1.0.2"
10515-
"@sinonjs/formatio" "^3.0.0"
10516-
"@sinonjs/samsam" "^2.1.1"
10517-
diff "^3.5.0"
10518-
lodash.get "^4.4.2"
10519-
lolex "^2.7.4"
10520-
nise "^1.4.5"
10521-
supports-color "^5.5.0"
10522-
type-detect "^4.0.8"
10523-
1052410450
sisteransi@^0.1.0:
1052510451
version "0.1.1"
1052610452
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce"
@@ -11142,10 +11068,6 @@ test-exclude@^4.2.1:
1114211068
read-pkg-up "^1.0.1"
1114311069
require-main-filename "^1.0.1"
1114411070

11145-
text-encoding@^0.6.4:
11146-
version "0.6.4"
11147-
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
11148-
1114911071
text-extensions@^1.0.0:
1115011072
version "1.7.0"
1115111073
resolved "https://registry.yarnpkg.com/text-extensions/-/text-extensions-1.7.0.tgz#faaaba2625ed746d568a23e4d0aacd9bf08a8b39"
@@ -11317,10 +11239,6 @@ type-check@~0.3.2:
1131711239
dependencies:
1131811240
prelude-ls "~1.1.2"
1131911241

11320-
[email protected], type-detect@^4.0.8:
11321-
version "4.0.8"
11322-
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
11323-
1132411242
type-is@~1.6.15, type-is@~1.6.16:
1132511243
version "1.6.16"
1132611244
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194"

0 commit comments

Comments
 (0)