Skip to content

Commit

Permalink
feat: Support jest snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jessy1092 committed Apr 11, 2017
1 parent 0392ab8 commit ceba068
Show file tree
Hide file tree
Showing 7 changed files with 1,674 additions and 358 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ component/

# gulpfile is transpile from gulpfile.babel.js
gulpfile.js

# test
coverage/
40 changes: 37 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"scripts": {
"start": "gulp dev",
"prepublish": "gulp transpile",
"storybook": "start-storybook -p 8000 -c storybook"
"storybook": "start-storybook -p 8000 -c storybook",
"test": "jest --coverage"
},
"engines": {
"node": ">=0.10.x"
Expand All @@ -48,19 +49,52 @@
"babelify": "^7.2.0",
"browserify": "^14.1.0",
"browserify-global-shim": "^1.0.3",
"enzyme": "^2.7.1",
"enzyme": "^2.8.0",
"enzyme-to-json": "^1.5.0",
"expect": "^1.20.2",
"gulp": "git://github.com/gulpjs/gulp.git#4.0",
"gulp-babel": "^6.1.2",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.1.0",
"gulp-util": "^3.0.6",
"identity-obj-proxy": "^3.0.0",
"jest": "^19.0.2",
"react-addons-test-utils": "^15.4.2",
"react-hot-loader": "3.0.0-beta.6",
"react-test-renderer": "^15.4.2",
"storybook-addon-specifications": "^1.0.16",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"dependencies": {}
"dependencies": {},
"jest": {
"setupFiles": [
"<rootDir>/storybook/__conf__/mockConfig.js"
],
"testMatch": [
"**/storybook/**/*.stories.js",
"**/src/**/*.spec.js"
],
"automock": false,
"globals": {
"__TESTS__": true
},
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react/",
"<rootDir>/node_modules/react-dom/",
"<rootDir>/node_modules/enzyme/",
"<rootDir>/node_modules/react-addons-test-utils/"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/storybook/__mocks__/file.js",
"\\.(css|less)$": "identity-obj-proxy"
},
"coveragePathIgnorePatterns": [
"<rootDir>/storybook/",
"<rootDir>/node_modules/"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
}
9 changes: 5 additions & 4 deletions storybook/__mocks__/facade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

export const expect = require('jest-matchers'); // eslint-disable-line global-require

export const action = () => () => {};

Expand All @@ -20,13 +22,12 @@ export const after = () => {};
export const before = () => {};

export const snapshot = (name, func) => {
it(name, () => func(expect));
it(name, () => func());
};

const createSnapshot = (name, story) => {
it(name, () => {
const tree = renderer.create(story).toJSON();
expect(tree).toMatchSnapshot();
expect(shallow(story)).toMatchSnapshot();
});
};

Expand Down
1 change: 0 additions & 1 deletion storybook/__mocks__/style.js

This file was deleted.

Loading

0 comments on commit ceba068

Please sign in to comment.