diff --git a/.eslintrc b/.eslintrc index 8d421e2f1..35f347856 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,9 @@ "node": true, "mocha": true }, + "ecmaFeatures": { + "jsx": true + }, "rules": { "id-length": 0, "new-cap": [2, { "capIsNewExceptions": ["AND"] }], diff --git a/package.json b/package.json index 259f09009..68806f14d 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,13 @@ "pretest": "npm run lint", "version": "npm run build", "clean": "rimraf build", - "lint": "eslint src/** test/**", + "lint": "eslint --ext js,jsx src test", "check": "npm run lint && npm run test:all", "build": "babel src --out-dir build", "test": "npm run test:only", - "test:only": "mocha --require withDom.js --compilers js:babel-core/register --recursive test/*.js --reporter dot", - "test:single": "mocha --require withDom.js --compilers js:babel-core/register --watch --reporter dot", - "test:watch": "mocha --require withDom.js --compilers js:babel-core/register --recursive test/*.js --watch --reporter dot", + "test:only": "mocha --recursive test --reporter dot", + "test:single": "mocha --watch --reporter dot", + "test:watch": "mocha --recursive test --watch --reporter dot", "test:env": "sh ./example-test.sh", "test:all": "npm run react:13 && npm run test:only && npm run react:14 && npm run test:only && npm run react:15 && npm run test:only", "react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", @@ -28,7 +28,7 @@ "docs:build": "npm run docs:prepare && gitbook build", "docs:watch": "npm run docs:prepare && gitbook serve", "docs:publish": "npm run docs:clean && npm run docs:build && cd _book && git init && git commit --allow-empty -m 'update book' && git fetch git@github.com:airbnb/enzyme.git gh-pages && git checkout -b gh-pages && git add . && git commit -am 'update book' && git push git@github.com:airbnb/enzyme.git gh-pages --force", - "travis": "babel-node ./node_modules/.bin/istanbul cover --report html _mocha -- --require withDom.js test --recursive" + "travis": "babel-node ./node_modules/.bin/istanbul cover --report html _mocha -- test --recursive" }, "repository": { "type": "git", diff --git a/src/Debug.js b/src/Debug.js index 9eb5c569e..42bca65fa 100644 --- a/src/Debug.js +++ b/src/Debug.js @@ -1,3 +1,8 @@ +import without from 'lodash/without'; +import escape from 'lodash/escape'; +import compact from 'lodash/compact'; +import objectValues from 'object.values'; + import { childrenOfNode, } from './ShallowTraversal'; @@ -13,11 +18,7 @@ import { internalInstance, propsOfNode, } from './Utils'; -import without from 'lodash/without'; -import escape from 'lodash/escape'; -import compact from 'lodash/compact'; import { REACT013 } from './version'; -import objectValues from 'object.values'; export function typeName(node) { return typeof node.type === 'function' diff --git a/src/MountedTraversal.js b/src/MountedTraversal.js index 83912b5c1..7b1f9da95 100644 --- a/src/MountedTraversal.js +++ b/src/MountedTraversal.js @@ -104,7 +104,7 @@ export function instHasProperty(inst, propKey, stringifiedPropValue) { return nodePropValue === propValue; } - return nodeProps.hasOwnProperty(propKey); + return Object.prototype.hasOwnProperty.call(nodeProps, propKey); } // called with private inst @@ -185,7 +185,7 @@ export function pathToNode(node, root) { // leaf node. if it isn't the node we are looking for, we pop. path.pop(); } - queue.push.apply(queue, children); + queue.push(...children); } return null; diff --git a/src/ReactWrapper.js b/src/ReactWrapper.jsx similarity index 100% rename from src/ReactWrapper.js rename to src/ReactWrapper.jsx diff --git a/test/.eslintrc b/test/.eslintrc index 4885145e3..eb5959112 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -7,5 +7,8 @@ "react/prefer-es6-class": 0, "react/prefer-stateless-function": 0, "react/prop-types": 0, + "import/no-extraneous-dependencies": [2, { + "devDependencies": true + }], } } diff --git a/test/ComplexSelector-spec.js b/test/ComplexSelector-spec.jsx similarity index 100% rename from test/ComplexSelector-spec.js rename to test/ComplexSelector-spec.jsx diff --git a/test/Debug-spec.js b/test/Debug-spec.jsx similarity index 100% rename from test/Debug-spec.js rename to test/Debug-spec.jsx diff --git a/test/ReactWrapper-spec.js b/test/ReactWrapper-spec.jsx similarity index 100% rename from test/ReactWrapper-spec.js rename to test/ReactWrapper-spec.jsx diff --git a/test/ShallowTraversal-spec.js b/test/ShallowTraversal-spec.jsx similarity index 100% rename from test/ShallowTraversal-spec.js rename to test/ShallowTraversal-spec.jsx diff --git a/test/ShallowWrapper-spec.js b/test/ShallowWrapper-spec.jsx similarity index 100% rename from test/ShallowWrapper-spec.js rename to test/ShallowWrapper-spec.jsx diff --git a/test/Utils-spec.js b/test/Utils-spec.jsx similarity index 97% rename from test/Utils-spec.js rename to test/Utils-spec.jsx index 41157f854..358eed824 100644 --- a/test/Utils-spec.js +++ b/test/Utils-spec.jsx @@ -1,7 +1,10 @@ -import { describeWithDOM, describeIf } from './_helpers.js'; +/* globals window */ + import React from 'react'; import { expect } from 'chai'; -import { mount } from '../src/'; + +import { describeWithDOM, describeIf } from './_helpers'; +import { mount } from '../src'; import { coercePropValue, getNode, @@ -143,11 +146,11 @@ describe('Utils', () => { it('should not match not equal nodes', () => { expect(nodeEqual(
child
, -
+
)).to.equal(false); expect(nodeEqual( -
, +
,
child
)).to.equal(false); }); @@ -155,28 +158,28 @@ describe('Utils', () => { it('should skip null children', () => { expect(nodeEqual(
{null}
, -
+
)).to.equal(true); }); it('should skip undefined children', () => { expect(nodeEqual(
{undefined}
, -
+
)).to.equal(true); }); it('should skip empty children', () => { expect(nodeEqual(
{[]}
, -
+
)).to.equal(true); }); it('should skip array of null children', () => { expect(nodeEqual(
{[null, null, null]}
, -
+
)).to.equal(true); }); diff --git a/test/_helpers.js b/test/_helpers.jsx similarity index 100% rename from test/_helpers.js rename to test/_helpers.jsx diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 000000000..7dac32bc8 --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,3 @@ +--require withDom.js +--compilers js:babel-core/register,jsx:babel-core/register +--extensions js,jsx