Skip to content

Commit 2632ab0

Browse files
committed
Add first tests, add prop-types dependency
1 parent 3c1e86b commit 2632ab0

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

package.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "./node_modules/.bin/babel ./src/ReactHTMLTableToExcel.jsx -o index.js",
8-
"prepublish": "npm run build"
8+
"prepublish": "npm run build",
9+
"client:test": "NODE_ENV=test jest",
10+
"client:test:watch": "NODE_ENV=test jest --watch"
911
},
1012
"repository": {
1113
"type": "git",
@@ -24,18 +26,39 @@
2426
"url": "https://github.com/zsusac/ReactHTMLTableToExcel/issues"
2527
},
2628
"homepage": "https://github.com/zsusac/ReactHTMLTableToExcel#readme",
29+
"jest": {
30+
"rootDir": "./",
31+
"moduleNameMapper": {
32+
"^.+\\.(css|less)$": "<rootDir>/CSSStub.js"
33+
},
34+
"collectCoverage": true,
35+
"coverageDirectory": "<rootDir>/../../coverage",
36+
"verbose": true,
37+
"coveragePathIgnorePatterns": [
38+
"<rootDir>/../../node_modules/"
39+
]
40+
},
2741
"devDependencies": {
2842
"babel-cli": "^6.24.1",
2943
"babel-eslint": "^7.2.3",
3044
"babel-preset-es2015": "^6.24.1",
3145
"babel-preset-react": "^6.24.1",
3246
"babel-preset-stage-0": "^6.24.1",
47+
"chai": "^3.5.0",
48+
"chai-enzyme": "^0.6.1",
49+
"enzyme": "^2.8.2",
3350
"eslint": "^3.19.0",
3451
"eslint-config-airbnb": "^14.1.0",
3552
"eslint-plugin-import": "^2.2.0",
3653
"eslint-plugin-jsx-a11y": "^5.0.1",
3754
"eslint-plugin-react": "^7.0.0",
38-
"react": "^15.5.4"
55+
"jest": "^20.0.1",
56+
"react": "^15.5.4",
57+
"react-dom": "^15.5.4",
58+
"react-test-renderer": "^15.5.4",
59+
"sinon": "^2.2.0"
3960
},
40-
"dependencies": {}
61+
"dependencies": {
62+
"prop-types": "^15.5.10"
63+
}
4164
}

src/ReactHTMLTableToExcel.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* global window, document, Blob */
2-
import React, { Component, PropTypes } from 'react';
2+
import React, { Component } from 'react';
3+
import PropTypes from 'prop-types';
34

45
const propTypes = {
56
table: PropTypes.string.isRequired,

test/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import chai, { expect } from 'chai';
3+
import chaiEnzyme from 'chai-enzyme';
4+
import { shallow } from 'enzyme';
5+
import sinon from 'sinon';
6+
import ReactHTMLTableToExcel from '../src/ReactHTMLTableToExcel';
7+
8+
chai.use(chaiEnzyme());
9+
10+
const props = {
11+
id: 'test-table-xls-button',
12+
className: 'download-table-xls-button',
13+
table: 'table-to-xls',
14+
filename: 'tablexls',
15+
sheet: 'tablexls',
16+
buttonText: 'Download as XLS',
17+
};
18+
19+
const container = shallow(<ReactHTMLTableToExcel {...props} />);
20+
21+
describe('tests for <ReactHTMLTableToExcel> container', () => {
22+
it('should render one button', () => {
23+
expect(container.find('button').length).to.equal(1);
24+
});
25+
26+
it('should render one button with the correct class applied', () => {
27+
expect(container.find('button').hasClass(props.className)).to.equal(true);
28+
});
29+
});

0 commit comments

Comments
 (0)