Skip to content

Commit

Permalink
Add jest and simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Lopin committed Mar 25, 2018
1 parent d3f9c17 commit b098a15
Show file tree
Hide file tree
Showing 6 changed files with 1,473 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"presets": ["react-hmre"]
},
"test": {
"presets": ["react", "es2015"],
"presets": ["env" ,"react", "es2015"],
"plugins": [
[ "babel-plugin-webpack-alias", { "config": "${PWD}/webpack.config.js" } ]
]
Expand Down
7 changes: 7 additions & 0 deletions __mocks__/electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
require: jest.genMockFunction(),
match: jest.genMockFunction(),
app: jest.genMockFunction(),
remote: jest.genMockFunction(),
dialog: jest.genMockFunction()
}
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"webpack": "webpack-dev-server --hot --inline --config webpack.config.js",
"compile": "grunt compile",
"test": "PWD=$(pwd) NODE_ENV=test ava --serial",
"jest": "jest",
"fix": "npm run lint --fix",
"lint": "eslint .",
"dev-start": "concurrently --kill-others \"npm run webpack\" \"npm run hot\""
Expand Down Expand Up @@ -96,11 +97,13 @@
"devDependencies": {
"ava": "^0.25.0",
"babel-core": "^6.14.0",
"babel-jest": "^22.4.3",
"babel-loader": "^6.2.0",
"babel-plugin-react-transform": "^2.0.0",
"babel-plugin-webpack-alias": "^2.1.1",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-react": "^6.24.1",
"babel-preset-react-hmre": "^1.0.1",
"babel-register": "^6.11.6",
"browser-env": "^3.2.5",
Expand All @@ -120,6 +123,8 @@
"grunt": "^0.4.5",
"grunt-electron-installer": "2.1.0",
"history": "^1.17.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^22.4.3",
"jsdom": "^9.4.2",
"json-loader": "^0.5.4",
"merge-stream": "^1.0.0",
Expand All @@ -130,6 +135,7 @@
"react-input-autosize": "^1.1.0",
"react-router": "^2.4.0",
"react-router-redux": "^4.0.4",
"react-test-renderer": "^15.6.2",
"standard": "^8.4.0",
"style-loader": "^0.12.4",
"stylus": "^0.52.4",
Expand All @@ -152,5 +158,11 @@
"./tests/helpers/setup-electron-mock.js"
],
"babel": "inherit"
},
"jest": {
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|styl)$": "identity-obj-proxy"
}
}
}
9 changes: 9 additions & 0 deletions tests/components/TagListItem.snapshot.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import renderer from 'react-test-renderer'
import TagListItem from 'browser/components/TagListItem'

it('TagListItem renders correctly', () => {
const tagListItem = renderer.create(<TagListItem name='Test' handleClickTagListItem={jest.fn()} />)

expect(tagListItem.toJSON()).toMatchSnapshot()
})
19 changes: 19 additions & 0 deletions tests/components/__snapshots__/TagListItem.snapshot.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TagListItem renders correctly 1`] = `
<button
className="tagList-item"
onClick={[Function]}
>
<span
className="tagList-item-name"
>
# Test
<span
className="tagList-item-count"
>
</span>
</span>
</button>
`;
Loading

0 comments on commit b098a15

Please sign in to comment.