Skip to content

Commit e2e494d

Browse files
authored
Merge pull request #19 from lutovich/tests-for-chart-re-rendering
Basic unit tests for chart re-rendering
2 parents d71a3bf + 0cf9009 commit e2e494d

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"react",
5+
"stage-1"
6+
]
7+
}

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
},
1818
"devDependencies": {
1919
"babel-eslint": "^4.1.3",
20+
"babel-jest": "^14.1.0",
21+
"babel-preset-es2015": "^6.13.2",
22+
"babel-preset-react": "^6.11.1",
23+
"babel-preset-stage-1": "^6.13.0",
2024
"eslint": "^1.6.0",
2125
"eslint-plugin-react": "^3.5.1",
2226
"gulp": "^3.9.0",
27+
"jest": "^14.1.0",
2328
"react": "^0.14.0",
2429
"react-component-gulp-tasks": "^0.7.6",
2530
"react-dom": "^0.14.0"
@@ -38,9 +43,12 @@
3843
"publish:site": "NODE_ENV=production gulp publish:examples",
3944
"release": "NODE_ENV=production gulp release",
4045
"start": "gulp dev",
41-
"test": "echo \"no tests yet\" && exit 0",
46+
"test": "jest",
4247
"watch": "gulp watch:lib"
4348
},
49+
"jest": {
50+
"automock": false
51+
},
4452
"keywords": [
4553
"react",
4654
"react-component"

src/__tests__/ChartTests.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import ChartComponent from "../Chart";
2+
3+
describe('Chart re-rendering', () => {
4+
5+
it('required when chart data changes', () => {
6+
const chart = new ChartComponent({type: 'bar', data: {}});
7+
const updateRequired = chart.shouldComponentUpdate({type: 'bar', data: {labels: ['a', 'b']}});
8+
expect(updateRequired).toBeTruthy();
9+
});
10+
11+
it('required when chart legend changes', () => {
12+
const chart = new ChartComponent({type: 'bar', legend: {display: false}});
13+
const updateRequired = chart.shouldComponentUpdate({type: 'bar', legend: {display: true}});
14+
expect(updateRequired).toBeTruthy();
15+
});
16+
17+
it('required when chart options change', () => {
18+
const chart = new ChartComponent({type: 'bar', options: {hover: {mode: 'single'}}});
19+
const updateRequired = chart.shouldComponentUpdate({type: 'bar', options: {hover: {mode: 'label'}}});
20+
expect(updateRequired).toBeTruthy();
21+
});
22+
23+
it('not required when width changes', () => {
24+
const chart = new ChartComponent({type: 'bar', width: 100});
25+
const updateRequired = chart.shouldComponentUpdate({type: 'bar', width: 200});
26+
expect(updateRequired).toBeFalsy();
27+
});
28+
29+
it('not required when height changes', () => {
30+
const chart = new ChartComponent({type: 'bar', height: 100});
31+
const updateRequired = chart.shouldComponentUpdate({type: 'bar', height: 200});
32+
expect(updateRequired).toBeFalsy();
33+
});
34+
35+
it('not required when data do not change and onElementsClick installed', () => {
36+
const chart = new ChartComponent({
37+
type: 'bar', data: {}, onElementsClick: () => {
38+
}
39+
});
40+
const updateRequired = chart.shouldComponentUpdate({
41+
type: 'bar', data: {}, onElementsClick: () => {
42+
}
43+
});
44+
expect(updateRequired).toBeFalsy();
45+
});
46+
});

0 commit comments

Comments
 (0)