Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"presets": ["airbnb"]
"presets": [
"react", "es2015"
]
}
1 change: 1 addition & 0 deletions build/jest/CSSStub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
1 change: 1 addition & 0 deletions build/jest/FileStub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "test-file-stub";
12 changes: 12 additions & 0 deletions build/jest/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"testRegex": ".*\\.test\\.js$",
"modulePaths": [
"<rootDir>"
],
"moduleNameMapper": {
"^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|svg|ttf|woff|woff2|mp4|webm)$": "build/jest/FileStub.js",
"^[./a-zA-Z0-9$_-]+\\.css$": "build/jest/CSSStub.js"
},
"verbose": true,
"rootDir": "../.."
}
42 changes: 12 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Example project with React + Enzyme + Jest",
"main": "build/index.js",
"scripts": {
"test": "jest"
"test": "jest --config=build/jest/config.json --watch"
},
"repository": {
"type": "git",
Expand All @@ -17,36 +17,18 @@
},
"homepage": "https://github.com/lelandrichardson/enzyme-example-jest#readme",
"devDependencies": {
"babel": "^6.3.26",
"babel-jest": "^6.0.1",
"babel-preset-airbnb": "^1.0.1",
"enzyme": "^2.0.0",
"jest": "^0.1.40",
"jest-cli": "^0.8.2",
"react": "^0.14.7",
"react-addons-test-utils": "^0.14.7"
"babel-core": "^6.14.0",
"babel-jest": "^15.0.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"enzyme": "^2.4.1",
"jest": "^15.1.1",
"jest-cli": "^15.1.1",
"react": "^15.3.1",
"react-addons-test-utils": "^15.3.1"
},
"dependencies": {
"react": "^0.14.7",
"react-dom": "^0.14.7"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"unmockedModulePathPatterns": [
"react",
"react-dom",
"react-addons-test-utils",
"fbjs",
"enzyme",
"cheerio",
"htmlparser2",
"underscore",
"lodash",
"domhandler",
"object.assign",
"define-properties",
"function-bind",
"object-keys"
]
"react": "^15.3.1",
"react-dom": "^15.3.1"
}
}
13 changes: 2 additions & 11 deletions src/Foo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { PropTypes } from 'react';
import React, { Component } from 'react';

const propTypes = {};

const defaultProps = {};

class Foo extends React.Component {
export default class Foo extends Component {
constructor(props) {
super(props);
}
Expand All @@ -15,8 +11,3 @@ class Foo extends React.Component {
);
}
}

Foo.propTypes = propTypes;
Foo.defaultProps = defaultProps;

export default Foo;
10 changes: 4 additions & 6 deletions src/__tests__/Foo-test.js → src/__tests__/Foo.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import React from 'react';
import { shallow, mount, render } from 'enzyme';

jest.dontMock('../Foo');

const Foo = require('../Foo');
import Foo from '../Foo';

describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
//expect(shallow(<Foo />).contains(<div className="foo" />)).toBe(true);
expect(shallow(<Foo />).contains(<div className="foo" />)).toBe(true);
});

it("contains spec with an expectation", function() {
//expect(shallow(<Foo />).is('.foo')).toBe(true);
expect(shallow(<Foo />).is('.foo')).toBe(true);
});

it("contains spec with an expectation", function() {
//expect(mount(<Foo />).find('.foo').length).toBe(1);
expect(mount(<Foo />).find('.foo').length).toBe(1);
});
});