Skip to content

Commit

Permalink
Added mocha example
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jsmey authored and jsmey committed Oct 21, 2017
1 parent e798b18 commit baefd2c
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/enzyme-example-mocha/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["airbnb"]
}
8 changes: 8 additions & 0 deletions packages/enzyme-example-mocha/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "airbnb",
"root": true,
"env": {
"node": true,
"mocha": true
}
}
22 changes: 22 additions & 0 deletions packages/enzyme-example-mocha/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Coverage
.coverage
.nyc_output
9 changes: 9 additions & 0 deletions packages/enzyme-example-mocha/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"reporter": [
"lcov",
"text-summary"
],
"extension": [
".jsx"
]
}
21 changes: 21 additions & 0 deletions packages/enzyme-example-mocha/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Leland Richardson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions packages/enzyme-example-mocha/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# enzyme-example-mocha
Example project with React + Enzyme + Mocha

# npm scripts
```
npm test
```
38 changes: 38 additions & 0 deletions packages/enzyme-example-mocha/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "enzyme-example-mocha",
"version": "0.1.0",
"description": "Example project with React + Enzyme + Mocha",
"scripts": {
"lint": "eslint ./src/**/*.js*",
"pretest": "npm run lint",
"test": "nyc mocha --require test/.setup.js --compilers js:babel-core/register src/*.spec.js*",
"test-watch": "npm test -- --watch"
},
"repository": {
"type": "git",
"url": "https://github.com/airbnb/enzyme.git"
},
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"homepage": "https://github.com/airbnb/enzyme.git",
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.0",
"babel-preset-airbnb": "^2.4.0",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"jsdom": "^11.3.0",
"mocha": "^3.5.3",
"nyc": "^11.2.1"
},
"dependencies": {
"chai": "^3.5.0",
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0"
}
}
5 changes: 5 additions & 0 deletions packages/enzyme-example-mocha/src/Foo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const Foo = () => <div className="foo" />;

export default Foo;
21 changes: 21 additions & 0 deletions packages/enzyme-example-mocha/src/Foo.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import Enzyme, { shallow, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { expect } from 'chai';
import Foo from '../src/Foo';

Enzyme.configure({ adapter: new Adapter() });

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

it('contains spec with an expectation', () => {
expect(shallow(<Foo />).is('.foo')).to.equal(true);
});

it('contains spec with an expectation', () => {
expect(mount(<Foo />).find('.foo').length).to.equal(1);
});
});
19 changes: 19 additions & 0 deletions packages/enzyme-example-mocha/test/.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { JSDOM } from 'jsdom';
import { expect } from 'chai';
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
Object.defineProperties(target, props);
}

global.expect = expect;
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);

0 comments on commit baefd2c

Please sign in to comment.