diff --git a/packages/enzyme-example-mocha/.babelrc b/packages/enzyme-example-mocha/.babelrc new file mode 100644 index 000000000..e0aceaae1 --- /dev/null +++ b/packages/enzyme-example-mocha/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["airbnb"] +} diff --git a/packages/enzyme-example-mocha/.eslintrc b/packages/enzyme-example-mocha/.eslintrc new file mode 100644 index 000000000..69b66a401 --- /dev/null +++ b/packages/enzyme-example-mocha/.eslintrc @@ -0,0 +1,8 @@ +{ + "extends": "airbnb", + "root": true, + "env": { + "node": true, + "mocha": true + } +} diff --git a/packages/enzyme-example-mocha/.gitignore b/packages/enzyme-example-mocha/.gitignore new file mode 100644 index 000000000..e521a0a09 --- /dev/null +++ b/packages/enzyme-example-mocha/.gitignore @@ -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 diff --git a/packages/enzyme-example-mocha/.nycrc b/packages/enzyme-example-mocha/.nycrc new file mode 100644 index 000000000..8b205c3da --- /dev/null +++ b/packages/enzyme-example-mocha/.nycrc @@ -0,0 +1,9 @@ +{ + "reporter": [ + "lcov", + "text-summary" + ], + "extension": [ + ".jsx" + ] +} diff --git a/packages/enzyme-example-mocha/LICENSE b/packages/enzyme-example-mocha/LICENSE new file mode 100644 index 000000000..0c373221e --- /dev/null +++ b/packages/enzyme-example-mocha/LICENSE @@ -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. diff --git a/packages/enzyme-example-mocha/README.md b/packages/enzyme-example-mocha/README.md new file mode 100644 index 000000000..b11ef9678 --- /dev/null +++ b/packages/enzyme-example-mocha/README.md @@ -0,0 +1,8 @@ +# enzyme-example-mocha +Example project with React + Enzyme + Mocha + +# npm scripts +``` +npm test + +``` diff --git a/packages/enzyme-example-mocha/package.json b/packages/enzyme-example-mocha/package.json new file mode 100644 index 000000000..da1e0403c --- /dev/null +++ b/packages/enzyme-example-mocha/package.json @@ -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 ", + "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" + } +} diff --git a/packages/enzyme-example-mocha/src/Foo.jsx b/packages/enzyme-example-mocha/src/Foo.jsx new file mode 100644 index 000000000..1a125b450 --- /dev/null +++ b/packages/enzyme-example-mocha/src/Foo.jsx @@ -0,0 +1,5 @@ +import React from 'react'; + +const Foo = () =>
; + +export default Foo; diff --git a/packages/enzyme-example-mocha/src/Foo.spec.jsx b/packages/enzyme-example-mocha/src/Foo.spec.jsx new file mode 100644 index 000000000..e3b76aeaa --- /dev/null +++ b/packages/enzyme-example-mocha/src/Foo.spec.jsx @@ -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().contains(
)).to.equal(true); + }); + + it('contains spec with an expectation', () => { + expect(shallow().is('.foo')).to.equal(true); + }); + + it('contains spec with an expectation', () => { + expect(mount().find('.foo').length).to.equal(1); + }); +}); diff --git a/packages/enzyme-example-mocha/test/.setup.js b/packages/enzyme-example-mocha/test/.setup.js new file mode 100644 index 000000000..19bfb1521 --- /dev/null +++ b/packages/enzyme-example-mocha/test/.setup.js @@ -0,0 +1,19 @@ +import { JSDOM } from 'jsdom'; +import { expect } from 'chai'; +const jsdom = new JSDOM(''); +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);