Skip to content

Commit baefd2c

Browse files
jsmeyjsmey
authored andcommitted
Added mocha example
adding eslint and nyc coverage cleaned up eslint errors use airbnb preset and fix .eslintrc removed unused dependencies removed unused eslint rules use chai expect
1 parent e798b18 commit baefd2c

File tree

10 files changed

+154
-0
lines changed

10 files changed

+154
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["airbnb"]
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "airbnb",
3+
"root": true,
4+
"env": {
5+
"node": true,
6+
"mocha": true
7+
}
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Dependency directory
12+
node_modules
13+
14+
# Optional npm cache directory
15+
.npm
16+
17+
# Optional REPL history
18+
.node_repl_history
19+
20+
# Coverage
21+
.coverage
22+
.nyc_output
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"reporter": [
3+
"lcov",
4+
"text-summary"
5+
],
6+
"extension": [
7+
".jsx"
8+
]
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Leland Richardson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# enzyme-example-mocha
2+
Example project with React + Enzyme + Mocha
3+
4+
# npm scripts
5+
```
6+
npm test
7+
8+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "enzyme-example-mocha",
3+
"version": "0.1.0",
4+
"description": "Example project with React + Enzyme + Mocha",
5+
"scripts": {
6+
"lint": "eslint ./src/**/*.js*",
7+
"pretest": "npm run lint",
8+
"test": "nyc mocha --require test/.setup.js --compilers js:babel-core/register src/*.spec.js*",
9+
"test-watch": "npm test -- --watch"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/airbnb/enzyme.git"
14+
},
15+
"author": "Leland Richardson <[email protected]>",
16+
"license": "MIT",
17+
"homepage": "https://github.com/airbnb/enzyme.git",
18+
"devDependencies": {
19+
"babel": "^6.23.0",
20+
"babel-core": "^6.26.0",
21+
"babel-preset-airbnb": "^2.4.0",
22+
"eslint": "^4.9.0",
23+
"eslint-config-airbnb": "^16.1.0",
24+
"eslint-plugin-import": "^2.8.0",
25+
"eslint-plugin-jsx-a11y": "^6.0.2",
26+
"eslint-plugin-react": "^7.4.0",
27+
"jsdom": "^11.3.0",
28+
"mocha": "^3.5.3",
29+
"nyc": "^11.2.1"
30+
},
31+
"dependencies": {
32+
"chai": "^3.5.0",
33+
"enzyme": "^3.0.0",
34+
"enzyme-adapter-react-16": "^1.0.0",
35+
"react": "^16.0.0",
36+
"react-dom": "^16.0.0"
37+
}
38+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
const Foo = () => <div className="foo" />;
4+
5+
export default Foo;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import Enzyme, { shallow, mount } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
4+
import { expect } from 'chai';
5+
import Foo from '../src/Foo';
6+
7+
Enzyme.configure({ adapter: new Adapter() });
8+
9+
describe('A suite', () => {
10+
it('contains spec with an expectation', () => {
11+
expect(shallow(<Foo />).contains(<div className="foo" />)).to.equal(true);
12+
});
13+
14+
it('contains spec with an expectation', () => {
15+
expect(shallow(<Foo />).is('.foo')).to.equal(true);
16+
});
17+
18+
it('contains spec with an expectation', () => {
19+
expect(mount(<Foo />).find('.foo').length).to.equal(1);
20+
});
21+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { JSDOM } from 'jsdom';
2+
import { expect } from 'chai';
3+
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
4+
const { window } = jsdom;
5+
6+
function copyProps(src, target) {
7+
const props = Object.getOwnPropertyNames(src)
8+
.filter(prop => typeof target[prop] === 'undefined')
9+
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
10+
Object.defineProperties(target, props);
11+
}
12+
13+
global.expect = expect;
14+
global.window = window;
15+
global.document = window.document;
16+
global.navigator = {
17+
userAgent: 'node.js',
18+
};
19+
copyProps(window, global);

0 commit comments

Comments
 (0)