Skip to content

Commit

Permalink
added test machinery and snapshots, build
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Mar 14, 2020
1 parent 0454b99 commit 6611b76
Show file tree
Hide file tree
Showing 7 changed files with 2,644 additions and 1,040 deletions.
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
};

2 changes: 1 addition & 1 deletion dist/react-csv-reader.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-csv-reader.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.6.3",
"@babel/preset-react": "^7.6.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"babel-jest": "^25.1.0",
"babel-loader": "^8.0.6",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
Expand All @@ -21,9 +22,11 @@
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"jest": "^25.1.0",
"prettier": "^1.18.2",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-test-renderer": "^16.13.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
},
Expand All @@ -34,7 +37,8 @@
},
"scripts": {
"build": "webpack -p",
"watch": "webpack --watch --progress"
"watch": "webpack --watch --progress",
"test": "jest"
},
"dependencies": {
"papaparse": "^5.1.0"
Expand Down
16 changes: 16 additions & 0 deletions src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Renders basic CSVReader 1`] = `
<div
className="csv-reader-input"
>
<input
accept=".csv, text/csv"
className="csv-input"
id={null}
onChange={[Function]}
style={Object {}}
type="file"
/>
</div>
`;
37 changes: 37 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react'
import renderer from 'react-test-renderer'
import CSVReader from './index'

test('Renders basic CSVReader', () => {
const component = renderer.create(<CSVReader onFileLoaded={() => {}} />)

let tree = component.toJSON()
expect(tree).toMatchSnapshot()
})

test('Renders CSVReader with all custom props', () => {
const papaparseOptions = {
header: true,
dynamicTyping: true,
skipEmptyLines: true,
transformHeader: header => header.toLowerCase().replace(/\W/g, '_'),
}

const component = renderer.create(
<CSVReader
accept=".csv, text/csv, .tsv, test/tsv"
cssClass="custom-csv-reader"
cssInputClass="custom-csv-input"
fileEncoding="iso-8859-1"
inputId="react-csv-reader"
inputStyle={{ color: 'red' }}
label="Select CSV with secret Death Star statistics"
onError={e => console.error(e)}
onFileLoaded={(data, fileName) => console.log(data, fileName)}
parserOptions={papaparseOptions}
/>,
)

let tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
Loading

0 comments on commit 6611b76

Please sign in to comment.