Skip to content

Commit 730851f

Browse files
committed
moar tests!
1 parent 06190e7 commit 730851f

File tree

9 files changed

+371
-93
lines changed

9 files changed

+371
-93
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'],
25+
frameworks: ['mocha', 'chai-spies', 'chai'],
2626
files: ['./test.js'],
2727
preprocessors: {'./test.js': 'webpack'},
2828
reporters: ['mocha'].concat(coverageReporters),

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"babel-preset-stage-0": "^6.24.1",
3939
"babel-register": "^6.26.0",
4040
"chai": "^4.1.2",
41+
"chai-spies": "^1.0.0",
4142
"codacy-coverage": "^3.0.0",
4243
"cross-env": "^5.2.0",
4344
"enzyme": "^3.3.0",
@@ -46,6 +47,7 @@
4647
"istanbul-instrumenter-loader": "^3.0.1",
4748
"karma": "^2.0.4",
4849
"karma-chai": "^0.1.0",
50+
"karma-chai-spies": "^0.1.4",
4951
"karma-chrome-launcher": "^2.2.0",
5052
"karma-coverage-istanbul-reporter": "^2.0.1",
5153
"karma-mocha": "^1.3.0",

test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import Enzyme from 'enzyme';
2-
import Adapter from 'enzyme-adapter-react-16';
1+
import chai from "chai";
2+
import spies from "chai-spies";
3+
import Enzyme from 'enzyme';
4+
import Adapter from 'enzyme-adapter-react-16';
5+
6+
chai.use(spies);
37

48
Enzyme.configure({adapter: new Adapter()});
59

tests/Scrollbars/getset.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import React from "react";
2+
import { render, unmountComponentAtNode } from "react-dom";
3+
import { Scrollbar } from "react-scrollbars-custom";
4+
5+
export default function createTests(scrollbarWidth) {
6+
describe("getset", () => {
7+
let node;
8+
beforeEach(() => {
9+
node = document.createElement("div");
10+
document.body.appendChild(node);
11+
});
12+
afterEach(() => {
13+
unmountComponentAtNode(node);
14+
document.body.removeChild(node);
15+
});
16+
17+
let sbRender = (cb) => render(<Scrollbar style={ {width: 100, height: 100} }>
18+
<div style={ {width: 200, height: 200} }></div>
19+
</Scrollbar>,
20+
node,
21+
cb);
22+
23+
describe("getters", function () {
24+
it("should return scrollTop",
25+
(done) => sbRender(function () {
26+
this.scrollTop = 50;
27+
expect(this.scrollTop).to.be.equal(50);
28+
expect(this.content.scrollTop).to.be.equal(50);
29+
30+
done();
31+
}));
32+
33+
it("should return scrollLeft",
34+
(done) => sbRender(function () {
35+
this.scrollLeft = 50;
36+
expect(this.scrollLeft).to.be.equal(50);
37+
expect(this.content.scrollLeft).to.be.equal(50);
38+
39+
done();
40+
}));
41+
42+
it("should return scrollHeight",
43+
(done) => sbRender(function () {
44+
expect(this.scrollHeight).to.be.equal(200);
45+
expect(this.content.scrollHeight).to.be.equal(200);
46+
47+
done();
48+
}));
49+
50+
it("should return scrollWidth",
51+
(done) => sbRender(function () {
52+
expect(this.scrollWidth).to.be.equal(200);
53+
expect(this.content.scrollWidth).to.be.equal(200);
54+
55+
done();
56+
}));
57+
58+
it("should return clientHeight",
59+
(done) => sbRender(function () {
60+
expect(this.clientHeight).to.be.equal(92);
61+
expect(this.content.clientHeight).to.be.equal(92);
62+
63+
done();
64+
}));
65+
66+
it("should return clientWidth",
67+
(done) => sbRender(function () {
68+
expect(this.clientWidth).to.be.equal(92);
69+
expect(this.content.clientWidth).to.be.equal(92);
70+
71+
done();
72+
}));
73+
});
74+
75+
describe("setters", function () {
76+
it("scrollTop/scrollToTop/scrollToBottom",
77+
(done) => sbRender(function () {
78+
this.scrollTop = 50;
79+
expect(this.scrollTop).to.be.equal(50);
80+
expect(this.content.scrollTop).to.be.equal(50);
81+
this.scrollToTop();
82+
expect(this.content.scrollTop).to.be.equal(0);
83+
this.scrollToBottom();
84+
expect(this.content.scrollTop).to.be.equal(this.content.scrollHeight - this.content.clientHeight);
85+
86+
done();
87+
}));
88+
89+
it("scrollLeft/scrollToLeft/scrollToRight",
90+
(done) => sbRender(function () {
91+
this.scrollLeft = 50;
92+
expect(this.scrollLeft).to.be.equal(50);
93+
expect(this.content.scrollLeft).to.be.equal(50);
94+
this.scrollToLeft();
95+
expect(this.content.scrollLeft).to.be.equal(0);
96+
this.scrollToRight();
97+
expect(this.content.scrollLeft).to.be.equal(this.content.scrollWidth - this.content.clientWidth);
98+
99+
done();
100+
}));
101+
102+
it("scrollHeight should not be settable",
103+
(done) => sbRender(function () {
104+
expect(() => {this.scrollHeight = 0;}).to.throw(TypeError);
105+
106+
done();
107+
}));
108+
109+
it("scrollWidth should not be settable",
110+
(done) => sbRender(function () {
111+
expect(() => {this.scrollWidth = 0;}).to.throw(TypeError);
112+
113+
done();
114+
}));
115+
116+
it("clientHeight should not be settable",
117+
(done) => sbRender(function () {
118+
expect(() => {this.clientHeight = 0;}).to.throw(TypeError);
119+
120+
done();
121+
}));
122+
123+
it("clientWidth should not be settable",
124+
(done) => sbRender(function () {
125+
expect(() => {this.clientWidth = 0;}).to.throw(TypeError);
126+
127+
done();
128+
}));
129+
});
130+
});
131+
}

tests/Scrollbars/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import rendering from "./rendering";
2+
import getset from "./getset";
3+
import scrolling from "./scrolling";
24

35
export default function createTests(scrollbarWidth) {
46
rendering(scrollbarWidth);
7+
getset(scrollbarWidth);
8+
scrolling(scrollbarWidth);
59
}

0 commit comments

Comments
 (0)