Skip to content

Commit f8a602b

Browse files
committed
jest's expect + sinon is better than chai
1 parent a76eb45 commit f8a602b

File tree

10 files changed

+137
-109
lines changed

10 files changed

+137
-109
lines changed

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function karmaConfig(config) {
2222
config.set({
2323
browsers: ['ChromeHeadless'],
2424
singleRun: true,
25-
frameworks: ['mocha', 'chai-spies', 'chai'],
25+
frameworks: ['mocha'],
2626
files: ['./test.js'],
2727
preprocessors: {'./test.js': 'webpack'},
2828
reporters: ['mocha'].concat(coverageReporters),

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@
3737
"babel-preset-react": "^6.24.1",
3838
"babel-preset-stage-0": "^6.24.1",
3939
"babel-register": "^6.26.0",
40-
"chai": "^4.1.2",
41-
"chai-spies": "^1.0.0",
4240
"codacy-coverage": "^3.0.0",
4341
"cross-env": "^5.2.0",
4442
"enzyme": "^3.3.0",
4543
"enzyme-adapter-react-16": "^1.1.1",
4644
"enzyme-to-json": "^3.3.4",
45+
"expect": "^23.4.0",
4746
"istanbul-instrumenter-loader": "^3.0.1",
4847
"karma": "^2.0.4",
49-
"karma-chai": "^0.1.0",
50-
"karma-chai-spies": "^0.1.4",
5148
"karma-chrome-launcher": "^2.2.0",
5249
"karma-coverage-istanbul-reporter": "^2.0.1",
5350
"karma-mocha": "^1.3.0",
@@ -59,6 +56,7 @@
5956
"react": "^16.4.1",
6057
"react-dom": "^16.4.1",
6158
"rimraf": "^2.6.2",
59+
"sinon": "^6.1.4",
6260
"webpack": "^4.15.1",
6361
"webpack-cli": "^3.0.8",
6462
"webpack-dev-server": "^3.1.4"
@@ -71,6 +69,6 @@
7169
"test:coverage": "cross-env NODE_ENV=test COVERAGE=true karma start --single-run",
7270
"push-codacy-coverage": "cat ./coverage/lcov.info | codacy-coverage -p .",
7371
"build": "rimraf lib && babel src -d dist",
74-
"prepublish": "npm test && npm run build"
72+
"prepublishOnly": "npm test && npm run build"
7573
}
7674
}

test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import chai from "chai";
2-
import spies from "chai-spies";
31
import Enzyme from 'enzyme';
42
import Adapter from 'enzyme-adapter-react-16';
53

6-
chai.use(spies);
7-
84
Enzyme.configure({adapter: new Adapter()});
95

106
const context = require.context('./tests', true, /\.spec\.js$/);

tests/Scrollbars/getset.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import expect from "expect";
12
import React from "react";
23
import { render, unmountComponentAtNode } from "react-dom";
34
import { Scrollbar } from "react-scrollbars-custom";
@@ -24,49 +25,49 @@ export default function createTests(scrollbarWidth) {
2425
it("should return scrollTop",
2526
(done) => sbRender(function () {
2627
this.scrollTop = 50;
27-
expect(this.scrollTop).to.be.equal(50);
28-
expect(this.content.scrollTop).to.be.equal(50);
28+
expect(this.scrollTop).toBe(50);
29+
expect(this.content.scrollTop).toBe(50);
2930

3031
done();
3132
}));
3233

3334
it("should return scrollLeft",
3435
(done) => sbRender(function () {
3536
this.scrollLeft = 50;
36-
expect(this.scrollLeft).to.be.equal(50);
37-
expect(this.content.scrollLeft).to.be.equal(50);
37+
expect(this.scrollLeft).toBe(50);
38+
expect(this.content.scrollLeft).toBe(50);
3839

3940
done();
4041
}));
4142

4243
it("should return scrollHeight",
4344
(done) => sbRender(function () {
44-
expect(this.scrollHeight).to.be.equal(200);
45-
expect(this.content.scrollHeight).to.be.equal(200);
45+
expect(this.scrollHeight).toBe(200);
46+
expect(this.content.scrollHeight).toBe(200);
4647

4748
done();
4849
}));
4950

5051
it("should return scrollWidth",
5152
(done) => sbRender(function () {
52-
expect(this.scrollWidth).to.be.equal(200);
53-
expect(this.content.scrollWidth).to.be.equal(200);
53+
expect(this.scrollWidth).toBe(200);
54+
expect(this.content.scrollWidth).toBe(200);
5455

5556
done();
5657
}));
5758

5859
it("should return clientHeight",
5960
(done) => sbRender(function () {
60-
expect(this.clientHeight).to.be.equal(92);
61-
expect(this.content.clientHeight).to.be.equal(92);
61+
expect(this.clientHeight).toBe(92);
62+
expect(this.content.clientHeight).toBe(92);
6263

6364
done();
6465
}));
6566

6667
it("should return clientWidth",
6768
(done) => sbRender(function () {
68-
expect(this.clientWidth).to.be.equal(92);
69-
expect(this.content.clientWidth).to.be.equal(92);
69+
expect(this.clientWidth).toBe(92);
70+
expect(this.content.clientWidth).toBe(92);
7071

7172
done();
7273
}));
@@ -76,53 +77,53 @@ export default function createTests(scrollbarWidth) {
7677
it("scrollTop/scrollToTop/scrollToBottom",
7778
(done) => sbRender(function () {
7879
this.scrollTop = 50;
79-
expect(this.scrollTop).to.be.equal(50);
80-
expect(this.content.scrollTop).to.be.equal(50);
80+
expect(this.scrollTop).toBe(50);
81+
expect(this.content.scrollTop).toBe(50);
8182
this.scrollToTop();
82-
expect(this.content.scrollTop).to.be.equal(0);
83+
expect(this.content.scrollTop).toBe(0);
8384
this.scrollToBottom();
84-
expect(this.content.scrollTop).to.be.equal(this.content.scrollHeight - this.content.clientHeight);
85+
expect(this.content.scrollTop).toBe(this.content.scrollHeight - this.content.clientHeight);
8586

8687
done();
8788
}));
8889

8990
it("scrollLeft/scrollToLeft/scrollToRight",
9091
(done) => sbRender(function () {
9192
this.scrollLeft = 50;
92-
expect(this.scrollLeft).to.be.equal(50);
93-
expect(this.content.scrollLeft).to.be.equal(50);
93+
expect(this.scrollLeft).toBe(50);
94+
expect(this.content.scrollLeft).toBe(50);
9495
this.scrollToLeft();
95-
expect(this.content.scrollLeft).to.be.equal(0);
96+
expect(this.content.scrollLeft).toBe(0);
9697
this.scrollToRight();
97-
expect(this.content.scrollLeft).to.be.equal(this.content.scrollWidth - this.content.clientWidth);
98+
expect(this.content.scrollLeft).toBe(this.content.scrollWidth - this.content.clientWidth);
9899

99100
done();
100101
}));
101102

102103
it("scrollHeight should not be settable",
103104
(done) => sbRender(function () {
104-
expect(() => {this.scrollHeight = 0;}).to.throw(TypeError);
105+
expect(() => {this.scrollHeight = 0;}).toThrow(TypeError);
105106

106107
done();
107108
}));
108109

109110
it("scrollWidth should not be settable",
110111
(done) => sbRender(function () {
111-
expect(() => {this.scrollWidth = 0;}).to.throw(TypeError);
112+
expect(() => {this.scrollWidth = 0;}).toThrow(TypeError);
112113

113114
done();
114115
}));
115116

116117
it("clientHeight should not be settable",
117118
(done) => sbRender(function () {
118-
expect(() => {this.clientHeight = 0;}).to.throw(TypeError);
119+
expect(() => {this.clientHeight = 0;}).toThrow(TypeError);
119120

120121
done();
121122
}));
122123

123124
it("clientWidth should not be settable",
124125
(done) => sbRender(function () {
125-
expect(() => {this.clientWidth = 0;}).to.throw(TypeError);
126+
expect(() => {this.clientWidth = 0;}).toThrow(TypeError);
126127

127128
done();
128129
}));

tests/Scrollbars/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import getset from "./getset";
12
import rendering from "./rendering";
2-
import getset from "./getset";
33
import scrolling from "./scrolling";
44

55
export default function createTests(scrollbarWidth) {

tests/Scrollbars/rendering.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import expect from "expect";
12
import React from "react";
23
import { findDOMNode, render, unmountComponentAtNode } from "react-dom";
34
import { Scrollbar } from "react-scrollbars-custom";
@@ -17,41 +18,41 @@ export default function createTests(scrollbarWidth) {
1718
describe("when <Scrollbar /> is rendered", function () {
1819
it("renders content wrapper", (done) => {
1920
render(<Scrollbar />, node, function () {
20-
expect(this.wrapper).to.be.an.instanceof(Node);
21+
expect(this.wrapper).toBeInstanceOf(Node);
2122

2223
done();
2324
});
2425
});
2526
it("renders content", (done) => {
2627
render(<Scrollbar />, node, function () {
27-
expect(this.content).to.be.an.instanceof(Node);
28+
expect(this.content).toBeInstanceOf(Node);
2829

2930
done();
3031
});
3132
});
3233
it("content should have an absolute positioning", (done) => {
3334
render(<Scrollbar />, node, function () {
34-
expect(this.content.style.position).to.be.equal("absolute");
35-
expect(this.content.style.top).to.be.equal("0px");
36-
expect(this.content.style.left).to.be.equal("0px");
37-
expect(this.content.style.right).to.be.equal("0px");
38-
expect(this.content.style.bottom).to.be.equal("0px");
35+
expect(this.content.style.position).toBe("absolute");
36+
expect(this.content.style.top).toBe("0px");
37+
expect(this.content.style.left).toBe("0px");
38+
expect(this.content.style.right).toBe("0px");
39+
expect(this.content.style.bottom).toBe("0px");
3940

4041
done();
4142
});
4243
});
4344
it("renders tracks", (done) => {
4445
render(<Scrollbar />, node, function () {
45-
expect(this.trackVertical).to.be.an.instanceof(Node);
46-
expect(this.trackHorizontal).to.be.an.instanceof(Node);
46+
expect(this.trackVertical).toBeInstanceOf(Node);
47+
expect(this.trackHorizontal).toBeInstanceOf(Node);
4748

4849
done();
4950
});
5051
});
5152
it("renders thumbs", (done) => {
5253
render(<Scrollbar />, node, function () {
53-
expect(this.thumbVertical).to.be.an.instanceof(Node);
54-
expect(this.thumbHorizontal).to.be.an.instanceof(Node);
54+
expect(this.thumbVertical).toBeInstanceOf(Node);
55+
expect(this.thumbHorizontal).toBeInstanceOf(Node);
5556

5657
done();
5758
});
@@ -64,8 +65,8 @@ export default function createTests(scrollbarWidth) {
6465
function () {
6566
setTimeout(() => {
6667
// 92 / 200 * 92 = 42.32
67-
expect(this.thumbVertical.style.height).to.be.equal("43px");
68-
expect(this.thumbHorizontal.style.width).to.be.equal("43px");
68+
expect(this.thumbVertical.style.height).toBe("43px");
69+
expect(this.thumbHorizontal.style.width).toBe("43px");
6970

7071
done();
7172
}, 50);
@@ -78,8 +79,8 @@ export default function createTests(scrollbarWidth) {
7879
node,
7980
function () {
8081
setTimeout(() => {
81-
expect(this.thumbVertical.style.height).to.be.equal("50px");
82-
expect(this.thumbHorizontal.style.width).to.be.equal("50px");
82+
expect(this.thumbVertical.style.height).toBe("50px");
83+
expect(this.thumbHorizontal.style.width).toBe("50px");
8384

8485
done();
8586
}, 50);
@@ -92,7 +93,7 @@ export default function createTests(scrollbarWidth) {
9293
render(<Scrollbar tagName="label" />,
9394
node,
9495
function () {
95-
expect(findDOMNode(this).tagName.toLowerCase()).to.be.equal("label");
96+
expect(findDOMNode(this).tagName.toLowerCase()).toBe("label");
9697

9798
done();
9899
});
@@ -104,8 +105,8 @@ export default function createTests(scrollbarWidth) {
104105
render(<Scrollbar style={ {maxWidth: "100%"} } />,
105106
node,
106107
function () {
107-
expect(findDOMNode(this).style.maxWidth).to.be.equal("100%");
108-
expect(findDOMNode(this).style.display).to.be.equal("grid");
108+
expect(findDOMNode(this).style.maxWidth).toBe("100%");
109+
expect(findDOMNode(this).style.display).toBe("grid");
109110

110111
done();
111112
});
@@ -120,8 +121,8 @@ export default function createTests(scrollbarWidth) {
120121
node,
121122
function () {
122123
setTimeout(() => {
123-
expect(this.trackVertical.style.display).to.be.equal("none");
124-
expect(this.trackHorizontal.style.display).to.be.equal("none");
124+
expect(this.trackVertical.style.display).toBe("none");
125+
expect(this.trackHorizontal.style.display).toBe("none");
125126

126127
done();
127128
}, 50);
@@ -135,8 +136,8 @@ export default function createTests(scrollbarWidth) {
135136
node,
136137
function () {
137138
setTimeout(() => {
138-
expect(this.trackVertical.style.display).to.not.be.equal("none");
139-
expect(this.trackHorizontal.style.display).to.not.be.equal("none");
139+
expect(this.trackVertical.style.display).not.toBe("none");
140+
expect(this.trackHorizontal.style.display).not.toBe("none");
140141

141142
done();
142143
}, 50);
@@ -150,7 +151,7 @@ export default function createTests(scrollbarWidth) {
150151
node,
151152
function () {
152153
setTimeout(() => {
153-
expect(this.trackVertical.style.display).to.not.be.equal("none");
154+
expect(this.trackVertical.style.display).not.toBe("none");
154155

155156
done();
156157
}, 50);
@@ -164,7 +165,7 @@ export default function createTests(scrollbarWidth) {
164165
node,
165166
function () {
166167
setTimeout(() => {
167-
expect(this.trackHorizontal.style.display).to.not.be.equal("none");
168+
expect(this.trackHorizontal.style.display).not.toBe("none");
168169

169170
done();
170171
}, 50);
@@ -180,12 +181,12 @@ export default function createTests(scrollbarWidth) {
180181
node,
181182
function () {
182183
setTimeout(() => {
183-
expect(this.trackVertical.style.display).to.be.equal("none");
184-
expect(this.content.style.overflowY).to.be.equal("hidden");
185-
expect(this.content.style.marginRight).to.be.equal("");
186-
expect(this.trackHorizontal.style.display).to.not.be.equal("none");
187-
expect(this.content.style.overflowX).to.not.be.equal("hidden");
188-
expect(this.content.style.marginBottom).to.not.be.equal("");
184+
expect(this.trackVertical.style.display).toBe("none");
185+
expect(this.content.style.overflowY).toBe("hidden");
186+
expect(this.content.style.marginRight).toBe("");
187+
expect(this.trackHorizontal.style.display).not.toBe("none");
188+
expect(this.content.style.overflowX).not.toBe("hidden");
189+
expect(this.content.style.marginBottom).not.toBe("");
189190

190191
done();
191192
}, 50);
@@ -201,12 +202,12 @@ export default function createTests(scrollbarWidth) {
201202
node,
202203
function () {
203204
setTimeout(() => {
204-
expect(this.trackVertical.style.display).to.not.be.equal("none");
205-
expect(this.content.style.overflowY).to.not.be.equal("hidden");
206-
expect(this.content.style.marginRight).to.not.be.equal("");
207-
expect(this.trackHorizontal.style.display).to.be.equal("none");
208-
expect(this.content.style.overflowX).to.be.equal("hidden");
209-
expect(this.content.style.marginBottom).to.be.equal("");
205+
expect(this.trackVertical.style.display).not.toBe("none");
206+
expect(this.content.style.overflowY).not.toBe("hidden");
207+
expect(this.content.style.marginRight).not.toBe("");
208+
expect(this.trackHorizontal.style.display).toBe("none");
209+
expect(this.content.style.overflowX).toBe("hidden");
210+
expect(this.content.style.marginBottom).toBe("");
210211

211212
done();
212213
}, 50);
@@ -222,13 +223,13 @@ export default function createTests(scrollbarWidth) {
222223
node,
223224
function () {
224225
setTimeout(() => {
225-
expect(this.trackHorizontal.style.display).to.be.equal("none");
226-
expect(this.trackVertical.style.display).to.be.equal("none");
227-
expect(this.content.style.overflowX).to.be.equal("hidden");
228-
expect(this.content.style.overflowY).to.be.equal("hidden");
229-
expect(this.content.style.overflow).to.be.equal("hidden");
230-
expect(this.content.style.marginBottom).to.be.equal("");
231-
expect(this.content.style.marginRight).to.be.equal("");
226+
expect(this.trackHorizontal.style.display).toBe("none");
227+
expect(this.trackVertical.style.display).toBe("none");
228+
expect(this.content.style.overflowX).toBe("hidden");
229+
expect(this.content.style.overflowY).toBe("hidden");
230+
expect(this.content.style.overflow).toBe("hidden");
231+
expect(this.content.style.marginBottom).toBe("");
232+
expect(this.content.style.marginRight).toBe("");
232233

233234
done();
234235
}, 50);

0 commit comments

Comments
 (0)