diff --git a/.eslintrc b/.eslintrc index 38dae815f..84535ebf2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -58,6 +58,7 @@ "react/jsx-no-undef": 0, "react/no-multi-comp": 0, "react/jsx-one-expression-per-line": 0, + "react/jsx-fragments": 0, }, }, ], diff --git a/.travis.yml b/.travis.yml index 09465f811..a968cc3b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,6 +75,7 @@ matrix: - node_js: "6" env: REACT=0.13 env: + - REACT=16.9 - REACT=16.8 - REACT=16.7 - REACT=16.6 diff --git a/docs/api/ReactWrapper/everyWhere.md b/docs/api/ReactWrapper/everyWhere.md index b185d938b..f8e972c59 100644 --- a/docs/api/ReactWrapper/everyWhere.md +++ b/docs/api/ReactWrapper/everyWhere.md @@ -25,9 +25,9 @@ const wrapper = mount((
)); -expect(wrapper.find('.foo').everyWhere(n => n.hasClass('foo'))).to.equal(true); -expect(wrapper.find('.foo').everyWhere(n => n.hasClass('qoo'))).to.equal(false); -expect(wrapper.find('.foo').everyWhere(n => n.hasClass('bar'))).to.equal(false); +expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('foo'))).to.equal(true); +expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('qoo'))).to.equal(false); +expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('bar'))).to.equal(false); ``` diff --git a/docs/api/ReactWrapper/filterWhere.md b/docs/api/ReactWrapper/filterWhere.md index e47d76d01..6786ea5a2 100644 --- a/docs/api/ReactWrapper/filterWhere.md +++ b/docs/api/ReactWrapper/filterWhere.md @@ -20,7 +20,7 @@ provided predicate function, return true. ```jsx const wrapper = mount(); -const complexComponents = wrapper.find('.foo').filterWhere(n => typeof n.type() !== 'string'); +const complexComponents = wrapper.find('.foo').filterWhere((n) => typeof n.type() !== 'string'); expect(complexComponents).to.have.lengthOf(4); ``` diff --git a/docs/api/ReactWrapper/findWhere.md b/docs/api/ReactWrapper/findWhere.md index 714bfcd34..785ccb1e0 100644 --- a/docs/api/ReactWrapper/findWhere.md +++ b/docs/api/ReactWrapper/findWhere.md @@ -20,7 +20,7 @@ nodes. ```jsx const wrapper = mount(); -const complexComponents = wrapper.findWhere(n => typeof n.type() !== 'string'); +const complexComponents = wrapper.findWhere((n) => typeof n.type() !== 'string'); expect(complexComponents).to.have.lengthOf(8); ``` diff --git a/docs/api/ReactWrapper/key.md b/docs/api/ReactWrapper/key.md index e95e36a03..d1725b543 100644 --- a/docs/api/ReactWrapper/key.md +++ b/docs/api/ReactWrapper/key.md @@ -8,7 +8,7 @@ Returns the key value for the node of the current wrapper. It must be a single-n ```jsx const wrapper = mount(( )).find('li'); expect(wrapper.at(0).key()).to.equal('foo'); diff --git a/docs/api/ReactWrapper/map.md b/docs/api/ReactWrapper/map.md index de2fb5e91..ce6e4fa69 100644 --- a/docs/api/ReactWrapper/map.md +++ b/docs/api/ReactWrapper/map.md @@ -29,7 +29,7 @@ const wrapper = mount(( )); -const texts = wrapper.find('.foo').map(node => node.text()); +const texts = wrapper.find('.foo').map((node) => node.text()); expect(texts).to.eql(['bax', 'bar', 'baz']); ``` diff --git a/docs/api/ReactWrapper/someWhere.md b/docs/api/ReactWrapper/someWhere.md index 936a45b51..83dd6ccd0 100644 --- a/docs/api/ReactWrapper/someWhere.md +++ b/docs/api/ReactWrapper/someWhere.md @@ -25,9 +25,9 @@ const wrapper = mount((
)); -expect(wrapper.find('.foo').someWhere(n => n.hasClass('qoo'))).to.equal(true); -expect(wrapper.find('.foo').someWhere(n => n.hasClass('foo'))).to.equal(true); -expect(wrapper.find('.foo').someWhere(n => n.hasClass('bar'))).to.equal(false); +expect(wrapper.find('.foo').someWhere((n) => n.hasClass('qoo'))).to.equal(true); +expect(wrapper.find('.foo').someWhere((n) => n.hasClass('foo'))).to.equal(true); +expect(wrapper.find('.foo').someWhere((n) => n.hasClass('bar'))).to.equal(false); ``` diff --git a/docs/api/ReactWrapper/tap.md b/docs/api/ReactWrapper/tap.md index 7ac1d7e07..afcd67aca 100644 --- a/docs/api/ReactWrapper/tap.md +++ b/docs/api/ReactWrapper/tap.md @@ -26,6 +26,6 @@ const result = mount((
  • zzz
  • )).find('li') - .tap(n => console.log(n.debug())) - .map(n => n.text()); + .tap((n) => console.log(n.debug())) + .map((n) => n.text()); ``` diff --git a/docs/api/ShallowWrapper/everyWhere.md b/docs/api/ShallowWrapper/everyWhere.md index 6f86920f4..b31285138 100644 --- a/docs/api/ShallowWrapper/everyWhere.md +++ b/docs/api/ShallowWrapper/everyWhere.md @@ -25,9 +25,9 @@ const wrapper = shallow((
    )); -expect(wrapper.find('.foo').everyWhere(n => n.hasClass('foo'))).to.equal(true); -expect(wrapper.find('.foo').everyWhere(n => n.hasClass('qoo'))).to.equal(false); -expect(wrapper.find('.foo').everyWhere(n => n.hasClass('bar'))).to.equal(false); +expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('foo'))).to.equal(true); +expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('qoo'))).to.equal(false); +expect(wrapper.find('.foo').everyWhere((n) => n.hasClass('bar'))).to.equal(false); ``` diff --git a/docs/api/ShallowWrapper/filterWhere.md b/docs/api/ShallowWrapper/filterWhere.md index 5081a48e8..61dff7740 100644 --- a/docs/api/ShallowWrapper/filterWhere.md +++ b/docs/api/ShallowWrapper/filterWhere.md @@ -20,7 +20,7 @@ provided predicate function, return true. ```jsx const wrapper = shallow(); -const complexFoo = wrapper.find('.foo').filterWhere(n => typeof n.type() !== 'string'); +const complexFoo = wrapper.find('.foo').filterWhere((n) => typeof n.type() !== 'string'); expect(complexFoo).to.have.lengthOf(4); ``` diff --git a/docs/api/ShallowWrapper/findWhere.md b/docs/api/ShallowWrapper/findWhere.md index eb790eaf1..520ad5e5c 100644 --- a/docs/api/ShallowWrapper/findWhere.md +++ b/docs/api/ShallowWrapper/findWhere.md @@ -20,7 +20,7 @@ nodes. ```jsx const wrapper = shallow(); -const complexComponents = wrapper.findWhere(n => n.type() !== 'string'); +const complexComponents = wrapper.findWhere((n) => n.type() !== 'string'); expect(complexComponents).to.have.lengthOf(8); ``` diff --git a/docs/api/ShallowWrapper/key.md b/docs/api/ShallowWrapper/key.md index 22aeb41c2..6eb68dfbe 100644 --- a/docs/api/ShallowWrapper/key.md +++ b/docs/api/ShallowWrapper/key.md @@ -8,7 +8,7 @@ Returns the key value for the node of the current wrapper. It must be a single-n ```jsx const wrapper = shallow((
      - {['foo', 'bar'].map(s =>
    • {s}
    • )} + {['foo', 'bar'].map((s) =>
    • {s}
    • )}
    )).find('li'); expect(wrapper.at(0).key()).to.equal('foo'); diff --git a/docs/api/ShallowWrapper/map.md b/docs/api/ShallowWrapper/map.md index a4b019702..b9c0d72e3 100644 --- a/docs/api/ShallowWrapper/map.md +++ b/docs/api/ShallowWrapper/map.md @@ -29,7 +29,7 @@ const wrapper = shallow(( )); -const texts = wrapper.find('.foo').map(node => node.text()); +const texts = wrapper.find('.foo').map((node) => node.text()); expect(texts).to.eql(['bax', 'bar', 'baz']); ``` diff --git a/docs/api/ShallowWrapper/someWhere.md b/docs/api/ShallowWrapper/someWhere.md index 8a174b5b9..3327c988f 100644 --- a/docs/api/ShallowWrapper/someWhere.md +++ b/docs/api/ShallowWrapper/someWhere.md @@ -25,9 +25,9 @@ const wrapper = shallow((
    )); -expect(wrapper.find('.foo').someWhere(n => n.hasClass('qoo'))).to.equal(true); -expect(wrapper.find('.foo').someWhere(n => n.hasClass('foo'))).to.equal(true); -expect(wrapper.find('.foo').someWhere(n => n.hasClass('bar'))).to.equal(false); +expect(wrapper.find('.foo').someWhere((n) => n.hasClass('qoo'))).to.equal(true); +expect(wrapper.find('.foo').someWhere((n) => n.hasClass('foo'))).to.equal(true); +expect(wrapper.find('.foo').someWhere((n) => n.hasClass('bar'))).to.equal(false); ``` diff --git a/docs/api/ShallowWrapper/tap.md b/docs/api/ShallowWrapper/tap.md index f3b4db30f..5e4c1fe42 100644 --- a/docs/api/ShallowWrapper/tap.md +++ b/docs/api/ShallowWrapper/tap.md @@ -26,6 +26,6 @@ const result = shallow((
  • zzz
  • )).find('li') - .tap(n => console.log(n.debug())) - .map(n => n.text()); + .tap((n) => console.log(n.debug())) + .map((n) => n.text()); ``` diff --git a/docs/guides/jsdom.md b/docs/guides/jsdom.md index 3bf25a28d..ef65d717c 100644 --- a/docs/guides/jsdom.md +++ b/docs/guides/jsdom.md @@ -59,7 +59,7 @@ global.navigator = { function copyProps(src, target) { const props = Object.getOwnPropertyNames(src) - .filter(prop => typeof target[prop] === 'undefined') + .filter((prop) => typeof target[prop] === 'undefined') .reduce((result, prop) => ({ ...result, [prop]: Object.getOwnPropertyDescriptor(src, prop), diff --git a/docs/guides/migration-from-2-to-3.md b/docs/guides/migration-from-2-to-3.md index be1d09c89..bfcf2e107 100644 --- a/docs/guides/migration-from-2-to-3.md +++ b/docs/guides/migration-from-2-to-3.md @@ -152,7 +152,7 @@ enzyme has a `.children()` method which is intended to return the rendered child When using `mount(...)`, it can sometimes be unclear exactly what this would mean. Consider for example the following react components: - + ```js class Box extends React.Component { render() { @@ -438,7 +438,7 @@ method. To get the wrapper that was returned by enzyme 2: ```js const wrapper = mount(); -const refWrapper = wrapper.findWhere(n => n.instance() === wrapper.ref('abc')); +const refWrapper = wrapper.findWhere((n) => n.instance() === wrapper.ref('abc')); ``` ## With `mount`, `.instance()` can be called at any level of the tree @@ -501,7 +501,7 @@ have found something that did indeed break, please file an issue with us. Thank enzyme v3 now returns **all** nodes in the result set and not just html nodes. Consider this example: - + ```js const HelpLink = ({ text, ...rest }) => {text}; diff --git a/docs/guides/react-native.md b/docs/guides/react-native.md index bf6cf44b3..f60b79a62 100644 --- a/docs/guides/react-native.md +++ b/docs/guides/react-native.md @@ -46,7 +46,7 @@ prop, that can be used a selector similar to `className` in standard React: ``` ```jsx -expect(wrapper.findWhere(node => node.prop('testID') === 'todo-item')).toExist(); +expect(wrapper.findWhere((node) => node.prop('testID') === 'todo-item')).toExist(); ``` ## Default example configuration for Jest and JSDOM replacement @@ -185,7 +185,7 @@ describe('todo-list', () => { const newTodoTextInput = wrapper.find('Input').first(); const addTodoButton = wrapper .find('Button') - .findWhere(w => w.text() === 'Add Todo') + .findWhere((w) => w.text() === 'Add Todo') .first(); newTodoTextInput.props().onChangeText(newTodoText); @@ -199,7 +199,7 @@ describe('todo-list', () => { // You can either check for a testID prop, similar to className in React: expect( - wrapper.findWhere(node => node.prop('testID') === 'todo-item'), + wrapper.findWhere((node) => node.prop('testID') === 'todo-item'), ).toExist(); // Or even just find a component itself, if you broke the JSX out into its own component: diff --git a/env.js b/env.js index f44ac26c7..c5c0ec0ec 100755 --- a/env.js +++ b/env.js @@ -6,13 +6,13 @@ const spawn = require('child_process').spawn; const rimraf = require('rimraf'); const semver = require('semver'); -const promisify = fn => new Promise((res, rej) => { +const promisify = (fn) => new Promise((res, rej) => { const done = (err, val) => (err ? rej(err) : res(val)); fn(done); }); -const getFile = fpath => promisify(cb => fs.readFile(fpath, 'utf8', cb)); +const getFile = (fpath) => promisify((cb) => fs.readFile(fpath, 'utf8', cb)); // const getFiles = fpath => promisify(cb => fs.readdir(fpath, cb)); -const getJSON = fpath => getFile(fpath).then(json => JSON.parse(json)); +const getJSON = (fpath) => getFile(fpath).then((json) => JSON.parse(json)); const writeFile = (fpath, src) => promisify((cb) => { console.log('writeFile', fpath, src); if (process.env.DEBUG) { @@ -25,7 +25,7 @@ const writeJSON = (fpath, json, pretty = false) => writeFile( fpath, (pretty ? JSON.stringify(json, null, 2) : JSON.stringify(json)) + '\n' ); -const primraf = fpath => promisify((cb) => { +const primraf = (fpath) => promisify((cb) => { console.log('rimraf', fpath); if (process.env.DEBUG) { cb(); @@ -104,7 +104,7 @@ const packagesToRemove = [ 'react-addons-test-utils', 'react-test-renderer', 'create-react-class', -].map(s => `./node_modules/${s}`); +].map((s) => `./node_modules/${s}`); const additionalDirsToRemove = [ 'node_modules/.bin/npm', @@ -116,7 +116,7 @@ const rmrfs = [] .concat(additionalDirsToRemove); Promise.resolve() - .then(() => Promise.all(rmrfs.map(s => primraf(s)))) + .then(() => Promise.all(rmrfs.map((s) => primraf(s)))) .then(() => run('npm', 'i')) .then(() => Promise.all([ getJSON(adapterPackageJsonPath), @@ -125,8 +125,8 @@ Promise.resolve() .then(([adapterJson, testJson]) => { const peerDeps = adapterJson.peerDependencies; const installs = Object.keys(peerDeps) - .filter(key => !key.startsWith('enzyme')) - .map(key => `${key}@${key.startsWith('react') ? reactVersion : peerDeps[key]}`); + .filter((key) => !key.startsWith('enzyme')) + .map((key) => `${key}@${key.startsWith('react') ? reactVersion : peerDeps[key]}`); if (process.env.RENDERER) { // eslint-disable-next-line no-param-reassign @@ -153,4 +153,4 @@ Promise.resolve() delete testJson.dependencies[adapterName]; return writeJSON(testPackageJsonPath, testJson, true); }) - .catch(err => console.error(err)); + .catch((err) => console.error(err)); diff --git a/package.json b/package.json index c82399ef7..357426ef3 100644 --- a/package.json +++ b/package.json @@ -69,8 +69,8 @@ "babel-register": "^6.26.0", "chai": "^4.2.0", "coveralls": "^2.13.3", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-markdown": "^1.0.0", @@ -86,7 +86,7 @@ "json-loader": "^0.5.7", "karma": "^1.3.0", "karma-chrome-launcher": "^1.0.1", - "karma-firefox-launcher": "^1.1.0", + "karma-firefox-launcher": "^1.2.0", "karma-mocha": "^1.3.0", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^1.8.1", @@ -95,8 +95,8 @@ "mocha-lcov-reporter": "^1.3.0", "nyc": "^10.3.2", "prop-types": "^15.7.2", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2", + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3", "semver": "^6.3.0", "webpack": "^1.15.0" }, diff --git a/packages/enzyme-adapter-react-13/.eslintrc b/packages/enzyme-adapter-react-13/.eslintrc index 804914eb1..a2d792f94 100644 --- a/packages/enzyme-adapter-react-13/.eslintrc +++ b/packages/enzyme-adapter-react-13/.eslintrc @@ -2,6 +2,7 @@ "extends": "airbnb", "root": true, "rules": { + "max-classes-per-file": 0, "max-len": 0, "react/no-find-dom-node": 0, "react/no-multi-comp": 0, diff --git a/packages/enzyme-adapter-react-13/package.json b/packages/enzyme-adapter-react-13/package.json index 535d813d2..b59e1883b 100644 --- a/packages/enzyme-adapter-react-13/package.json +++ b/packages/enzyme-adapter-react-13/package.json @@ -49,13 +49,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js b/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js index 434bb16fc..f9ba3c46f 100644 --- a/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js +++ b/packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js @@ -47,7 +47,7 @@ const getEmptyElementType = (() => { const createShallowRenderer = function createRendererCompatible() { const renderer = TestUtils.createRenderer(); - renderer.render = (originalRender => function contextCompatibleRender(node, context = {}) { + renderer.render = ((originalRender) => function contextCompatibleRender(node, context = {}) { ReactContext.current = context; originalRender.call(this, React.createElement(node.type, node.props), context); ReactContext.current = {}; diff --git a/packages/enzyme-adapter-react-14/package.json b/packages/enzyme-adapter-react-14/package.json index a9b5c7498..53dfb752f 100644 --- a/packages/enzyme-adapter-react-14/package.json +++ b/packages/enzyme-adapter-react-14/package.json @@ -52,13 +52,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js b/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js index 4715958a4..4316855f5 100644 --- a/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js +++ b/packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js @@ -152,7 +152,7 @@ class ReactFourteenAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => instanceToTree(inst._reactInternalInstance), + toTree: (inst) => instanceToTree(inst._reactInternalInstance), getMountWrapperInstance: () => instance, }), }; diff --git a/packages/enzyme-adapter-react-15.4/package.json b/packages/enzyme-adapter-react-15.4/package.json index bf2a587cf..a5265d662 100644 --- a/packages/enzyme-adapter-react-15.4/package.json +++ b/packages/enzyme-adapter-react-15.4/package.json @@ -53,13 +53,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js b/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js index e4104547e..069ee0404 100644 --- a/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js +++ b/packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js @@ -187,7 +187,7 @@ class ReactFifteenFourAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => instanceToTree(inst._reactInternalInstance), + toTree: (inst) => instanceToTree(inst._reactInternalInstance), getMountWrapperInstance: () => instance, }), }; diff --git a/packages/enzyme-adapter-react-15/package.json b/packages/enzyme-adapter-react-15/package.json index 46d785699..92a3e0dd8 100644 --- a/packages/enzyme-adapter-react-15/package.json +++ b/packages/enzyme-adapter-react-15/package.json @@ -52,13 +52,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js b/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js index 50b98b8e2..0efd3ae69 100644 --- a/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js +++ b/packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js @@ -187,7 +187,7 @@ class ReactFifteenAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => instanceToTree(inst._reactInternalInstance), + toTree: (inst) => instanceToTree(inst._reactInternalInstance), getMountWrapperInstance: () => instance, }), }; diff --git a/packages/enzyme-adapter-react-16.1/.eslintrc b/packages/enzyme-adapter-react-16.1/.eslintrc index 268f4a8da..6b22e05cf 100644 --- a/packages/enzyme-adapter-react-16.1/.eslintrc +++ b/packages/enzyme-adapter-react-16.1/.eslintrc @@ -2,6 +2,7 @@ "extends": "airbnb", "root": true, "rules": { + "max-classes-per-file": 0, "max-len": 0, "react/no-deprecated": 0, "react/no-find-dom-node": 0, diff --git a/packages/enzyme-adapter-react-16.1/package.json b/packages/enzyme-adapter-react-16.1/package.json index 318134d57..f2652f789 100644 --- a/packages/enzyme-adapter-react-16.1/package.json +++ b/packages/enzyme-adapter-react-16.1/package.json @@ -52,13 +52,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js b/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js index aad993511..186f09b4d 100644 --- a/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js +++ b/packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js @@ -308,7 +308,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter { }, simulateError(nodeHierarchy, rootNode, error) { const { instance: catchingInstance } = nodeHierarchy - .find(x => x.instance && x.instance.componentDidCatch) || {}; + .find((x) => x.instance && x.instance.componentDidCatch) || {}; simulateError( error, @@ -336,7 +336,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => toTree(inst._reactInternalFiber), + toTree: (inst) => toTree(inst._reactInternalFiber), getMountWrapperInstance: () => instance, }), }; @@ -415,7 +415,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter { ref: cachedNode.ref, instance: renderer._instance, rendered: Array.isArray(output) - ? flatten(output).map(el => elementToTree(el)) + ? flatten(output).map((el) => elementToTree(el)) : elementToTree(output), }; }, diff --git a/packages/enzyme-adapter-react-16.2/.eslintrc b/packages/enzyme-adapter-react-16.2/.eslintrc index b964afed1..1f264e608 100644 --- a/packages/enzyme-adapter-react-16.2/.eslintrc +++ b/packages/enzyme-adapter-react-16.2/.eslintrc @@ -2,6 +2,7 @@ "extends": "airbnb", "root": true, "rules": { + "max-classes-per-file": 0, "max-len": 0, "react/no-deprecated": 0, "react/no-find-dom-node": 0, diff --git a/packages/enzyme-adapter-react-16.2/package.json b/packages/enzyme-adapter-react-16.2/package.json index bab8153db..70a461d33 100644 --- a/packages/enzyme-adapter-react-16.2/package.json +++ b/packages/enzyme-adapter-react-16.2/package.json @@ -53,13 +53,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js b/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js index 78cb4a7ac..16554555f 100644 --- a/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js +++ b/packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js @@ -310,7 +310,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter { }, simulateError(nodeHierarchy, rootNode, error) { const { instance: catchingInstance } = nodeHierarchy - .find(x => x.instance && x.instance.componentDidCatch) || {}; + .find((x) => x.instance && x.instance.componentDidCatch) || {}; simulateError( error, @@ -338,7 +338,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => toTree(inst._reactInternalFiber), + toTree: (inst) => toTree(inst._reactInternalFiber), getMountWrapperInstance: () => instance, }), }; @@ -417,7 +417,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter { ref: cachedNode.ref, instance: renderer._instance, rendered: Array.isArray(output) - ? flatten(output).map(el => elementToTree(el)) + ? flatten(output).map((el) => elementToTree(el)) : elementToTree(output), }; }, diff --git a/packages/enzyme-adapter-react-16.3/package.json b/packages/enzyme-adapter-react-16.3/package.json index e62c0ad2d..3cbafd9f9 100644 --- a/packages/enzyme-adapter-react-16.3/package.json +++ b/packages/enzyme-adapter-react-16.3/package.json @@ -53,13 +53,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js b/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js index 9087b0e87..7da9142bd 100644 --- a/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js +++ b/packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js @@ -329,7 +329,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter { }, simulateError(nodeHierarchy, rootNode, error) { const { instance: catchingInstance } = nodeHierarchy - .find(x => x.instance && x.instance.componentDidCatch) || {}; + .find((x) => x.instance && x.instance.componentDidCatch) || {}; simulateError( error, @@ -357,7 +357,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => toTree(inst._reactInternalFiber), + toTree: (inst) => toTree(inst._reactInternalFiber), getMountWrapperInstance: () => instance, }), }; @@ -381,7 +381,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter { } else if (isContextProvider(el)) { providerValues.set(el.type, el.props.value); const MockProvider = Object.assign( - props => props.children, + (props) => props.children, el.type, ); return withSetStateAllowed(() => renderer.render({ ...el, type: MockProvider })); @@ -391,7 +391,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter { ? providerValues.get(Provider) : getProviderDefaultValue(Provider); const MockConsumer = Object.assign( - props => props.children(value), + (props) => props.children(value), el.type, ); return withSetStateAllowed(() => renderer.render({ ...el, type: MockConsumer })); @@ -430,7 +430,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter { ref: cachedNode.ref, instance: renderer._instance, rendered: Array.isArray(output) - ? flatten(output).map(el => elementToTree(el)) + ? flatten(output).map((el) => elementToTree(el)) : elementToTree(output), }; }, diff --git a/packages/enzyme-adapter-react-16/.eslintrc b/packages/enzyme-adapter-react-16/.eslintrc index b75e0ee52..51b2fe6c8 100644 --- a/packages/enzyme-adapter-react-16/.eslintrc +++ b/packages/enzyme-adapter-react-16/.eslintrc @@ -2,6 +2,7 @@ "extends": "airbnb", "root": true, "rules": { + "max-classes-per-file": 0, "max-len": 0, "import/no-extraneous-dependencies": 2, "import/no-unresolved": 2, diff --git a/packages/enzyme-adapter-react-16/package.json b/packages/enzyme-adapter-react-16/package.json index 9930e06ed..02ee2e4a4 100644 --- a/packages/enzyme-adapter-react-16/package.json +++ b/packages/enzyme-adapter-react-16/package.json @@ -55,13 +55,13 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js index 2c30af373..9fff69198 100644 --- a/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js +++ b/packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js @@ -303,7 +303,7 @@ function replaceLazyWithFallback(node, fallback) { return null; } if (Array.isArray(node)) { - return node.map(el => replaceLazyWithFallback(el, fallback)); + return node.map((el) => replaceLazyWithFallback(el, fallback)); } if (isLazy(node.type)) { return fallback; @@ -491,7 +491,7 @@ class ReactSixteenAdapter extends EnzymeAdapter { return { ...this, ...getWrappingComponentMountRenderer({ - toTree: inst => toTree(inst._reactInternalFiber), + toTree: (inst) => toTree(inst._reactInternalFiber), getMountWrapperInstance: () => instance, }), }; @@ -523,7 +523,7 @@ class ReactSixteenAdapter extends EnzymeAdapter { if (isStateful(Component)) { wrappedComponent = class extends Component {}; // eslint-disable-line react/prefer-stateless-function if (compare) { - wrappedComponent.prototype.shouldComponentUpdate = nextProps => !compare(this.props, nextProps); + wrappedComponent.prototype.shouldComponentUpdate = (nextProps) => !compare(this.props, nextProps); } else { wrappedComponent.prototype.isPureReactComponent = true; } @@ -592,7 +592,7 @@ class ReactSixteenAdapter extends EnzymeAdapter { } else if (isContextProvider(el)) { providerValues.set(el.type, el.props.value); const MockProvider = Object.assign( - props => props.children, + (props) => props.children, el.type, ); return withSetStateAllowed(() => renderer.render({ ...el, type: MockProvider })); @@ -602,7 +602,7 @@ class ReactSixteenAdapter extends EnzymeAdapter { ? providerValues.get(Provider) : getProviderDefaultValue(Provider); const MockConsumer = Object.assign( - props => props.children(value), + (props) => props.children(value), el.type, ); return withSetStateAllowed(() => renderer.render({ ...el, type: MockConsumer })); @@ -684,7 +684,7 @@ class ReactSixteenAdapter extends EnzymeAdapter { ref: cachedNode.ref, instance: renderer._instance, rendered: Array.isArray(output) - ? flatten(output).map(el => elementToTree(el)) + ? flatten(output).map((el) => elementToTree(el)) : elementToTree(output), }; }, diff --git a/packages/enzyme-adapter-react-16/src/detectFiberTags.js b/packages/enzyme-adapter-react-16/src/detectFiberTags.js index 92c3cce84..b59f79c41 100644 --- a/packages/enzyme-adapter-react-16/src/detectFiberTags.js +++ b/packages/enzyme-adapter-react-16/src/detectFiberTags.js @@ -44,7 +44,7 @@ module.exports = function detectFiberTags() { const supportsContext = typeof React.createContext !== 'undefined'; const supportsForwardRef = typeof React.forwardRef !== 'undefined'; const supportsMemo = typeof React.memo !== 'undefined'; - const supportsProfiler = typeof React.unstable_Profiler !== 'undefined'; + const supportsProfiler = typeof React.unstable_Profiler !== 'undefined' || typeof React.Profiler !== 'undefined'; const supportsSuspense = typeof React.Suspense !== 'undefined'; const supportsLazy = typeof React.lazy !== 'undefined'; @@ -99,7 +99,7 @@ module.exports = function detectFiberTags() { ? getFiber(React.createElement(FwdRef)).tag : -1, Profiler: supportsProfiler - ? getFiber(React.createElement(React.unstable_Profiler, { id: 'mock', onRender() {} })).tag + ? getFiber(React.createElement((React.Profiler || React.unstable_Profiler), { id: 'mock', onRender() {} })).tag : -1, Suspense: supportsSuspense ? getFiber(React.createElement(React.Suspense, { fallback: false })).tag diff --git a/packages/enzyme-adapter-react-helper/package.json b/packages/enzyme-adapter-react-helper/package.json index 73b480c39..07ad9bfae 100644 --- a/packages/enzyme-adapter-react-helper/package.json +++ b/packages/enzyme-adapter-react-helper/package.json @@ -43,14 +43,14 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "enzyme": "^3.0.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", "react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0 || ^16.3.0-0 || ^16.4.0-0", - "safe-publish-latest": "^1.1.2" + "safe-publish-latest": "^1.1.3" }, "peerDependencies": { "enzyme": "^3.0.0", diff --git a/packages/enzyme-adapter-utils/package.json b/packages/enzyme-adapter-utils/package.json index eb26a4065..22085e3ec 100644 --- a/packages/enzyme-adapter-utils/package.json +++ b/packages/enzyme-adapter-utils/package.json @@ -49,13 +49,13 @@ "babel-cli": "^6.26.0", "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-adapter-utils/src/Utils.js b/packages/enzyme-adapter-utils/src/Utils.js index 83671c99d..e2a6efff5 100644 --- a/packages/enzyme-adapter-utils/src/Utils.js +++ b/packages/enzyme-adapter-utils/src/Utils.js @@ -209,7 +209,7 @@ export function elementToTree(el, recurse = elementToTree) { const { children } = props; let rendered = null; if (isArrayLike(children)) { - rendered = flatten(children).map(x => recurse(x)); + rendered = flatten(children).map((x) => recurse(x)); } else if (typeof children !== 'undefined') { rendered = recurse(children); } @@ -253,7 +253,7 @@ export function findElement(el, predicate) { } const { rendered } = el; if (isArrayLike(rendered)) { - return mapFind(rendered, x => findElement(x, predicate), x => typeof x !== 'undefined'); + return mapFind(rendered, (x) => findElement(x, predicate), (x) => typeof x !== 'undefined'); } return findElement(rendered, predicate); } @@ -274,7 +274,7 @@ export function getComponentStack( getNodeType = nodeTypeFromType, getDisplayName = displayNameOfNode, ) { - const tuples = hierarchy.filter(node => node.type !== RootFinder).map(x => [ + const tuples = hierarchy.filter((node) => node.type !== RootFinder).map((x) => [ getNodeType(x.type), getDisplayName(x), ]).concat([[ @@ -322,14 +322,14 @@ export function getMaskedContext(contextTypes, unmaskedContext) { if (!contextTypes || !unmaskedContext) { return {}; } - return fromEntries(Object.keys(contextTypes).map(key => [key, unmaskedContext[key]])); + return fromEntries(Object.keys(contextTypes).map((key) => [key, unmaskedContext[key]])); } export function getNodeFromRootFinder(isCustomComponent, tree, options) { if (!isCustomComponent(options.wrappingComponent)) { return tree.rendered; } - const rootFinder = findElement(tree, node => node.type === RootFinder); + const rootFinder = findElement(tree, (node) => node.type === RootFinder); if (!rootFinder) { throw new Error('`wrappingComponent` must render its children!'); } diff --git a/packages/enzyme-adapter-utils/src/createMountWrapper.jsx b/packages/enzyme-adapter-utils/src/createMountWrapper.jsx index 3d9cc138c..307caabd1 100644 --- a/packages/enzyme-adapter-utils/src/createMountWrapper.jsx +++ b/packages/enzyme-adapter-utils/src/createMountWrapper.jsx @@ -87,16 +87,18 @@ export default function createMountWrapper(node, options = {}) { } setChildContext(context) { - return new Promise(resolve => this.setState({ context }, resolve)); + return new Promise((resolve) => this.setState({ context }, resolve)); } render() { const { Component } = this.props; const { mount, props, wrappingComponentProps } = this.state; if (!mount) return null; + // eslint-disable-next-line react/jsx-props-no-spreading const component = ; if (WrappingComponent) { return ( + // eslint-disable-next-line react/jsx-props-no-spreading {component} diff --git a/packages/enzyme-example-mocha/package.json b/packages/enzyme-example-mocha/package.json index e3381e061..b27cad627 100644 --- a/packages/enzyme-example-mocha/package.json +++ b/packages/enzyme-example-mocha/package.json @@ -20,8 +20,8 @@ "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", "babel-register": "^6.26.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", @@ -30,7 +30,7 @@ "mocha": "^3.5.3", "nyc": "^11.4.1", "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "safe-publish-latest": "^1.1.3" }, "dependencies": { "chai": "^4.1.2", diff --git a/packages/enzyme-shallow-equal/package.json b/packages/enzyme-shallow-equal/package.json index 2d6e9a114..87c88dd24 100644 --- a/packages/enzyme-shallow-equal/package.json +++ b/packages/enzyme-shallow-equal/package.json @@ -43,11 +43,11 @@ "babel-cli": "^6.26.0", "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", - "eslint": "^5.16.0", - "eslint-config-airbnb-base": "^13.1.0", + "eslint": "^6.3.0", + "eslint-config-airbnb-base": "^14.0.0", "eslint-plugin-import": "^2.18.2", "in-publish": "^2.0.0", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme-test-suite/.eslintrc b/packages/enzyme-test-suite/.eslintrc index 30b705142..6c7c505a5 100644 --- a/packages/enzyme-test-suite/.eslintrc +++ b/packages/enzyme-test-suite/.eslintrc @@ -12,9 +12,11 @@ }, }, "rules": { + "max-classes-per-file": 0, "max-len": 0, "no-param-reassign": 0, "padded-blocks": 0, + "react/jsx-props-no-spreading": 0, "react/no-did-mount-set-state": 0, "react/no-will-update-set-state": 0, "react/no-multi-comp": 0, @@ -31,6 +33,7 @@ "jsx-a11y/anchor-is-valid": 0, "jsx-a11y/label-has-for": 0, "jsx-a11y/label-has-associated-control": 0, + "jsx-a11y/control-has-associated-label": 0, "react/jsx-curly-brace-presence": 0, "react/no-danger": 1, "react/jsx-one-expression-per-line": 0, diff --git a/packages/enzyme-test-suite/package.json b/packages/enzyme-test-suite/package.json index 7134a4991..a37ee473b 100644 --- a/packages/enzyme-test-suite/package.json +++ b/packages/enzyme-test-suite/package.json @@ -44,6 +44,7 @@ "object.assign": "^4.1.0", "prop-types": "^15.7.2", "react-is": "^16.8.6", + "safe-publish-latest": "^1.1.3", "semver": "^5.7.0", "sinon": "^5.1.1", "sinon-sandbox": "^2.0.0" @@ -53,8 +54,8 @@ "react-dom": "^15.5.0" }, "devDependencies": { - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-mocha": "^5.3.0", diff --git a/packages/enzyme-test-suite/test/Adapter-spec.jsx b/packages/enzyme-test-suite/test/Adapter-spec.jsx index 6b33d84f6..a94284d1f 100644 --- a/packages/enzyme-test-suite/test/Adapter-spec.jsx +++ b/packages/enzyme-test-suite/test/Adapter-spec.jsx @@ -31,7 +31,7 @@ import { itIf, describeWithDOM, describeIf } from './_helpers'; const { adapter } = get(); -const prettyFormat = x => inspect(x).replace(/,/g, ',\n'); +const prettyFormat = (x) => inspect(x).replace(/,/g, ',\n'); // Kind of hacky, but we nullify all the instances to test the tree structure // with jasmine's deep equality function, and test the instances separate. We @@ -988,7 +988,7 @@ describe('Adapter', () => { }); describe('provides node displayNames', () => { - const getDisplayName = el => adapter.displayNameOfNode(adapter.elementToNode(el)); + const getDisplayName = (el) => adapter.displayNameOfNode(adapter.elementToNode(el)); itIf(is('> 0.13'), 'supports stateless function components', () => { const SFC = () => null; @@ -1048,7 +1048,7 @@ describe('Adapter', () => { expect(getDisplayName()).to.equal('Profiler'); }); - itIf(is('>= 16.6'), 'supports ConcurrentMode', () => { + itIf((is('>= 16.6') && is('<16.9')), 'supports ConcurrentMode', () => { expect(getDisplayName()).to.equal('ConcurrentMode'); }); diff --git a/packages/enzyme-test-suite/test/Debug-spec.jsx b/packages/enzyme-test-suite/test/Debug-spec.jsx index 196a967e0..cbf736e3f 100644 --- a/packages/enzyme-test-suite/test/Debug-spec.jsx +++ b/packages/enzyme-test-suite/test/Debug-spec.jsx @@ -26,7 +26,7 @@ import { is } from './_helpers/version'; const { adapter } = get(); -const debugElement = element => debugNode(adapter.elementToNode(element)); +const debugElement = (element) => debugNode(adapter.elementToNode(element)); describe('debug', () => { wrap() @@ -818,7 +818,7 @@ describe('debug', () => {
    {function Foo() { /* hi */ }} {} - {arrow => arrow('function')} + {(arrow) => arrow('function')} {[1, 2, NaN]} {function (anonymous) {}} {{ a: 'b' }} diff --git a/packages/enzyme-test-suite/test/RSTTraversal-spec.jsx b/packages/enzyme-test-suite/test/RSTTraversal-spec.jsx index efc05a415..b691fb59d 100644 --- a/packages/enzyme-test-suite/test/RSTTraversal-spec.jsx +++ b/packages/enzyme-test-suite/test/RSTTraversal-spec.jsx @@ -115,7 +115,7 @@ describe('RSTTraversal', () => { )); treeForEach(node, spy); expect(spy).to.have.property('callCount', 3); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB]); }); @@ -141,7 +141,7 @@ describe('RSTTraversal', () => { )); treeForEach(node, spy); expect(spy).to.have.property('callCount', 5); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB, divC, divD]); }); @@ -160,7 +160,7 @@ describe('RSTTraversal', () => { )); treeForEach(node, spy); expect(spy).to.have.property('callCount', 3); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB]); }); @@ -186,7 +186,7 @@ describe('RSTTraversal', () => { )); treeForEach(node, spy); expect(spy).to.have.property('callCount', 5); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB, divC, divD]); }); @@ -205,7 +205,7 @@ describe('RSTTraversal', () => { )); treeForEach(node, spy); expect(spy).to.have.property('callCount', 3); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB]); }); @@ -231,7 +231,7 @@ describe('RSTTraversal', () => { )); treeForEach(node, spy); expect(spy).to.have.property('callCount', 5); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB, divC, divD]); }); @@ -275,7 +275,7 @@ describe('RSTTraversal', () => { treeForEach(node, spy); expect(spy).to.have.property('callCount', 3); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB]); }); @@ -298,7 +298,7 @@ describe('RSTTraversal', () => { treeForEach(node, spy); expect(spy).to.have.property('callCount', 5); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB, divC, divD]); }); @@ -317,7 +317,7 @@ describe('RSTTraversal', () => { treeForEach(node, spy); expect(spy).to.have.property('callCount', 3); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB]); }); @@ -340,7 +340,7 @@ describe('RSTTraversal', () => { treeForEach(node, spy); expect(spy).to.have.property('callCount', 5); - const nodes = spy.args.map(arg => arg[0]); + const nodes = spy.args.map((arg) => arg[0]); expect(nodes).to.deep.equal([node, divA, divB, divC, divD]); }); }); @@ -397,8 +397,8 @@ describe('RSTTraversal', () => { }); it('filters for truthiness', () => { - expect(treeFilter(tree, node => node.type === 'nav').length).to.equal(1); - expect(treeFilter(tree, node => node.type === 'button').length).to.equal(2); + expect(treeFilter(tree, (node) => node.type === 'nav').length).to.equal(1); + expect(treeFilter(tree, (node) => node.type === 'button').length).to.equal(2); }); }); diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx index 007a8de7b..7f7e73894 100644 --- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx @@ -283,9 +283,9 @@ describeWithDOM('mount', () => { function Component() { return ( - {value1 => ( + {(value1) => ( - {value2 => ( + {(value2) => (
    Value 1: {value1}; Value 2: {value2}
    )}
    @@ -367,7 +367,7 @@ describeWithDOM('mount', () => { const Bar = () => null; wrap() .withConsoleThrows() - .withOverride(() => getAdapter(), 'isValidElementType', () => val => val === Foo) + .withOverride(() => getAdapter(), 'isValidElementType', () => (val) => val === Foo) .it('with isValidElementType defined on the Adapter', () => { expect(() => { mount(); @@ -499,7 +499,7 @@ describeWithDOM('mount', () => { class Foo extends React.Component { render() { return ( - {value => {value}} + {(value) => {value}} ); } } @@ -512,7 +512,7 @@ describeWithDOM('mount', () => { it('can render a as the root', () => { const wrapper = mount( - {value =>
    {value}
    }
    + {(value) =>
    {value}
    }
    , ); expect(wrapper.text()).to.equal('cool'); @@ -523,12 +523,12 @@ describeWithDOM('mount', () => { it('can render a as the root', () => { const wrapper = mount( - {value =>
    {value}
    }
    , + {(value) =>
    {value}
    }
    , ); expect(wrapper.text()).to.equal('hello'); wrapper.setProps({ - children: value =>
    Value is: {value}
    , + children: (value) =>
    Value is: {value}
    , }); expect(wrapper.text()).to.equal('Value is: hello'); }); @@ -1541,6 +1541,14 @@ describeWithDOM('mount', () => { }); describe('lifecycle methods', () => { + const errorToThrow = new EvalError('threw an error!'); + // in React 16.0 - 16.2 and 16.9+, and some older nodes, the actual error thrown isn't reported. + const reactError = new Error('An error was thrown inside one of your components, but React doesn\'t know what it was. This is likely due to browser flakiness. React does its best to preserve the "Pause on exceptions" behavior of the DevTools, which requires some DEV-mode only tricks. It\'s possible that these don\'t work in your browser. Try triggering the error in production mode, or switching to a modern browser. If you suspect that this is actually an issue with React, please file an issue.'); + const properErrorMessage = (error) => error instanceof Error && ( + error.message === errorToThrow.message + || error.message === reactError.message + ); + describeIf(is('>= 16.3'), 'getDerivedStateFromProps', () => { let spy; @@ -1794,14 +1802,6 @@ describeWithDOM('mount', () => { describeIf(is('>= 16'), 'componentDidCatch', () => { describe('errors inside an error boundary', () => { - const errorToThrow = new EvalError('threw an error!'); - // in React 16.0 - 16.2, and some older nodes, the actual error thrown isn't reported. - const reactError = new Error('An error was thrown inside one of your components, but React doesn\'t know what it was. This is likely due to browser flakiness. React does its best to preserve the "Pause on exceptions" behavior of the DevTools, which requires some DEV-mode only tricks. It\'s possible that these don\'t work in your browser. Try triggering the error in production mode, or switching to a modern browser. If you suspect that this is actually an issue with React, please file an issue.'); - const properErrorMessage = error => error instanceof Error && ( - error.message === errorToThrow.message - || error.message === reactError.message - ); - const hasFragments = is('>= 16.2'); const MaybeFragment = hasFragments ? Fragment : 'main'; @@ -1972,8 +1972,6 @@ describeWithDOM('mount', () => { describeIf(is('>= 16.6'), 'getDerivedStateFromError', () => { describe('errors inside an error boundary', () => { - const errorToThrow = new EvalError('threw an error!'); - function Thrower({ throws }) { if (throws) { throw errorToThrow; @@ -2035,7 +2033,7 @@ describeWithDOM('mount', () => { mount(); expect(true).to.equal(false, 'this line should not be reached'); } catch (error) { - expect(error).to.equal(errorToThrow); + expect(error).to.satisfy(properErrorMessage); } }); }); @@ -2099,7 +2097,7 @@ describeWithDOM('mount', () => { expect(spy.args).to.be.an('array').and.have.lengthOf(1); const [[actualError]] = spy.args; - expect(actualError).to.equal(errorToThrow); + expect(actualError).to.satisfy(properErrorMessage); }); it('works when the root is an SFC', () => { @@ -2116,14 +2114,12 @@ describeWithDOM('mount', () => { expect(spy.args).to.be.an('array').and.have.lengthOf(1); const [[actualError]] = spy.args; - expect(actualError).to.equal(errorToThrow); + expect(actualError).to.satisfy(properErrorMessage); }); }); }); describeIf(is('>= 16.6'), 'getDerivedStateFromError and componentDidCatch combined', () => { - - const errorToThrow = new EvalError('threw an error!'); const expectedInfo = { componentStack: ` in Thrower (created by ErrorBoundary) @@ -2203,12 +2199,13 @@ describeWithDOM('mount', () => { wrapper.setState({ throws: true }); expect(lifecycleSpy).to.have.property('callCount', 4); - expect(lifecycleSpy.args).to.deep.equal([ - ['render'], - ['getDerivedStateFromError', errorToThrow], - ['render'], - ['componentDidCatch', errorToThrow, expectedInfo], - ]); + const [first, second, third, fourth] = lifecycleSpy.args; + expect(first).to.deep.equal(['render']); + expect(second).to.satisfy(([name, error, ...rest]) => name === 'getDerivedStateFromError' + && properErrorMessage(error) + && rest.length === 0); + expect(third).to.deep.equal(['render']); + expect(fourth).to.satisfy(([name, error, info]) => name === 'componentDidCatch' && properErrorMessage(error) && isEqual(info, expectedInfo)); expect(stateSpy).to.have.property('callCount', 1); expect(stateSpy.args).to.deep.equal([ @@ -2313,14 +2310,20 @@ describeWithDOM('mount', () => { spy.resetHistory(); - expect(() => wrapper.setState({ throws: true })).to.throw(errorToThrow); + try { + wrapper.setState({ throws: true }); + expect('should never get here').to.equal(false); + } catch (e) { + expect(e).to.satisfy(properErrorMessage); + } expect(spy).to.have.property('callCount', 3); - expect(spy.args).to.deep.equal([ - ['render'], - ['getDerivedStateFromError', errorToThrow], - ['render'], - ]); + const [first, second, third] = spy.args; + expect(first).to.deep.equal(['render']); + expect(second).to.satisfy(([name, arg, ...rest]) => name === 'getDerivedStateFromError' + && properErrorMessage(arg) + && rest.length === 0); + expect(third).to.deep.equal(['render']); }); it('renders again on simulated error', () => { diff --git a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx index 25e2fb2be..946932d6f 100644 --- a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx @@ -296,9 +296,9 @@ describe('shallow', () => { function Component() { return ( - {value1 => ( + {(value1) => ( - {value2 => ( + {(value2) => (
    Value 1: {value1}; Value 2: {value2}
    )}
    @@ -376,7 +376,7 @@ describe('shallow', () => { const Bar = () => null; wrap() .withConsoleThrows() - .withOverride(() => getAdapter(), 'isValidElementType', () => val => val === Foo) + .withOverride(() => getAdapter(), 'isValidElementType', () => (val) => val === Foo) .it('with isValidElementType defined on the Adapter', () => { expect(() => { shallow(); @@ -436,7 +436,7 @@ describe('shallow', () => { render() { return ( - {value => {value}} + {(value) => {value}} ); } @@ -480,7 +480,7 @@ describe('shallow', () => { const wrapper = shallow( - {value =>
    {value}
    } + {(value) =>
    {value}
    }
    , ); @@ -495,7 +495,7 @@ describe('shallow', () => { const wrapper = shallow( - {value =>
    {value}
    } + {(value) =>
    {value}
    }
    , ); @@ -511,7 +511,7 @@ describe('shallow', () => { it('can be rendered as the root', () => { const wrapper = shallow( - {value => {value}} + {(value) => {value}} , ); expect(wrapper.debug()).to.eql(` @@ -524,10 +524,10 @@ describe('shallow', () => { it('supports changing the children', () => { const wrapper = shallow( - {value => {value}} + {(value) => {value}} , ); - wrapper.setProps({ children: value => Changed: {value} }); + wrapper.setProps({ children: (value) => Changed: {value} }); expect(wrapper.find(DivRenderer).dive().text()).to.eql('Changed: cool'); }); }); @@ -545,7 +545,7 @@ describe('shallow', () => { render() { return ( - {value => {value}} + {(value) => {value}} ); } diff --git a/packages/enzyme-test-suite/test/Utils-spec.jsx b/packages/enzyme-test-suite/test/Utils-spec.jsx index a6e2e76ec..c6a2a27cb 100644 --- a/packages/enzyme-test-suite/test/Utils-spec.jsx +++ b/packages/enzyme-test-suite/test/Utils-spec.jsx @@ -733,11 +733,11 @@ describe('Utils', () => { ]; it('returns true when renderedDive receives nodes that render validEmpty values', () => { - emptyNodetestData.forEach(node => expect(renderedDive(node)).to.equal(true)); + emptyNodetestData.forEach((node) => expect(renderedDive(node)).to.equal(true)); }); it('returns false when renderedDive receives nodes that render non-valid empty values', () => { - nonEmptyNodeData.forEach(node => expect(renderedDive(node)).to.equal(false)); + nonEmptyNodeData.forEach((node) => expect(renderedDive(node)).to.equal(false)); }); }); diff --git a/packages/enzyme-test-suite/test/_helpers/react-compat.js b/packages/enzyme-test-suite/test/_helpers/react-compat.js index a5d06b2f9..f265092fd 100644 --- a/packages/enzyme-test-suite/test/_helpers/react-compat.js +++ b/packages/enzyme-test-suite/test/_helpers/react-compat.js @@ -18,6 +18,7 @@ let Fragment; let StrictMode; let AsyncMode; let ConcurrentMode; +let createRoot; let Profiler; let PureComponent; let Suspense; @@ -83,7 +84,9 @@ if (is('^16.3.0-0')) { AsyncMode = null; } -if (is('^16.4.0-0')) { +if (is('^16.9.0-0')) { + ({ Profiler } = require('react')); +} else if (is('^16.4.0-0')) { ({ unstable_Profiler: Profiler, } = require('react')); @@ -93,18 +96,32 @@ if (is('^16.4.0-0')) { if (is('^16.6.0-0')) { ({ - unstable_ConcurrentMode: ConcurrentMode, Suspense, lazy, memo, } = require('react')); } else { - ConcurrentMode = null; Suspense = null; lazy = null; memo = null; } +if (is('^16.6.0-0') && !is('^16.9.0-0')) { + ({ + unstable_ConcurrentMode: ConcurrentMode, + } = require('react')); +} else { + ConcurrentMode = null; +} + +if (is('^16.9.0-0')) { + ({ + unstable_createRoot: createRoot, + } = require('react')); +} else { + createRoot = null; +} + if (is('^16.8.0-0')) { ({ useCallback, @@ -145,6 +162,7 @@ export { createPortal, createContext, createRef, + createRoot, forwardRef, Fragment, StrictMode, diff --git a/packages/enzyme-test-suite/test/_helpers/realArrowFunction.js b/packages/enzyme-test-suite/test/_helpers/realArrowFunction.js index 8e004fd3e..f6d4928ab 100644 --- a/packages/enzyme-test-suite/test/_helpers/realArrowFunction.js +++ b/packages/enzyme-test-suite/test/_helpers/realArrowFunction.js @@ -2,5 +2,5 @@ try { // eslint-disable-next-line global-require module.exports = require('./untranspiledArrowFunction'); } catch (e) { - module.exports = x => () => x; + module.exports = (x) => () => x; } diff --git a/packages/enzyme-test-suite/test/_helpers/selectors.js b/packages/enzyme-test-suite/test/_helpers/selectors.js index a16b80c39..1b313b974 100644 --- a/packages/enzyme-test-suite/test/_helpers/selectors.js +++ b/packages/enzyme-test-suite/test/_helpers/selectors.js @@ -1,3 +1,3 @@ -export const getElementPropSelector = prop => x => x.props[prop]; +export const getElementPropSelector = (prop) => (x) => x.props[prop]; -export const getWrapperPropSelector = prop => x => x.prop(prop); +export const getWrapperPropSelector = (prop) => (x) => x.prop(prop); diff --git a/packages/enzyme-test-suite/test/_helpers/untranspiledArrowFunction.js b/packages/enzyme-test-suite/test/_helpers/untranspiledArrowFunction.js index 5a86b7ae6..67ef1adc1 100644 --- a/packages/enzyme-test-suite/test/_helpers/untranspiledArrowFunction.js +++ b/packages/enzyme-test-suite/test/_helpers/untranspiledArrowFunction.js @@ -1,3 +1,3 @@ // this file is ignored in babelrc, specifically so that tests will be able to run // on a real arrow function that lacks a .prototype -module.exports = x => () => x; +module.exports = (x) => () => x; diff --git a/packages/enzyme-test-suite/test/adapter-utils-spec.jsx b/packages/enzyme-test-suite/test/adapter-utils-spec.jsx index 80815e321..cc0246af8 100644 --- a/packages/enzyme-test-suite/test/adapter-utils-spec.jsx +++ b/packages/enzyme-test-suite/test/adapter-utils-spec.jsx @@ -224,20 +224,20 @@ describe('enzyme-adapter-utils', () => { ); it('finds an element in the render tree using a predicate', () => { - expect(findElement(tree, node => node.type === Target)).to.eql(target); + expect(findElement(tree, (node) => node.type === Target)).to.eql(target); }); it('returns undefined if the element cannot be found', () => { - expect(findElement(tree, node => node.type === Unfound)).to.equal(undefined); + expect(findElement(tree, (node) => node.type === Unfound)).to.equal(undefined); }); it('returns undefined if some non-element is passed', () => { - expect(findElement({}, node => node.type === Target)).to.equal(undefined); + expect(findElement({}, (node) => node.type === Target)).to.equal(undefined); }); }); describe('getNodeFromRootFinder', () => { - const isCustomComponent = component => typeof component === 'function'; + const isCustomComponent = (component) => typeof component === 'function'; class Target extends React.Component { render() { return null; } } class WrappingComponent extends React.Component { render() { return null; } } diff --git a/packages/enzyme-test-suite/test/selector-spec.jsx b/packages/enzyme-test-suite/test/selector-spec.jsx index c3f026ce3..769f719d4 100644 --- a/packages/enzyme-test-suite/test/selector-spec.jsx +++ b/packages/enzyme-test-suite/test/selector-spec.jsx @@ -298,7 +298,7 @@ describe('selectors', () => { expect(wrapper.find('.to-find')).to.have.lengthOf(3); const toFind = wrapper.find('.to-find + .sibling'); expect(toFind).to.have.lengthOf(2); - toFind.map(found => expect(found.text()).to.equal('Adjacent')); + toFind.map((found) => expect(found.text()).to.equal('Adjacent')); }); it('simple general siblings', () => { @@ -336,7 +336,7 @@ describe('selectors', () => { const spans = wrapper.find('span'); const siblings = wrapper.find('span ~ span'); expect(spans.length - 2).to.equal(siblings.length); - siblings.map(sibling => expect(sibling.text()).to.not.equal('Top')); + siblings.map((sibling) => expect(sibling.text()).to.not.equal('Top')); }); it('handles using general siblings on root', () => { diff --git a/packages/enzyme-test-suite/test/shared/hooks/custom.jsx b/packages/enzyme-test-suite/test/shared/hooks/custom.jsx index 8aad509d3..4a70358a1 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/custom.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/custom.jsx @@ -20,8 +20,8 @@ export default function describeCustomHooks({ describe('custom hook : useCounter', () => { function useCounter({ initialCount = 0, step = 1 } = {}) { const [count, setCount] = useState(initialCount); - const increment = () => setCount(c => c + step); - const decrement = () => setCount(c => c - step); + const increment = () => setCount((c) => c + step); + const decrement = () => setCount((c) => c - step); return { count, increment, decrement }; } // testing custom hooks with renderProps diff --git a/packages/enzyme-test-suite/test/shared/hooks/useCallback.jsx b/packages/enzyme-test-suite/test/shared/hooks/useCallback.jsx index dfdbbb0df..19a5cdc40 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/useCallback.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/useCallback.jsx @@ -21,14 +21,14 @@ export default function describeUseCallback({ } function ComponentUsingCallbackHook({ onChange }) { - const callback = useCallback(value => onChange(value), [onChange]); + const callback = useCallback((value) => onChange(value), [onChange]); return ( ); } function ComponentUsingCallbackHookWithRelatedProp({ onChange, relatedProp }) { - const callback = useCallback(value => onChange(value), [onChange, relatedProp]); + const callback = useCallback((value) => onChange(value), [onChange, relatedProp]); return ( ); diff --git a/packages/enzyme-test-suite/test/shared/hooks/useDebugValue.jsx b/packages/enzyme-test-suite/test/shared/hooks/useDebugValue.jsx index 479102ed1..7cb0323ea 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/useDebugValue.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/useDebugValue.jsx @@ -22,7 +22,7 @@ export default function describeUseDebugValue({ return (
    {value}
    ); } - function ComponentUsingDebugValueAndCallback({ value, fn = x => `debug value: ${x}` }) { + function ComponentUsingDebugValueAndCallback({ value, fn = (x) => `debug value: ${x}` }) { useDebugValue(value, fn); return (
    {value}
    ); diff --git a/packages/enzyme-test-suite/test/shared/hooks/useEffect.jsx b/packages/enzyme-test-suite/test/shared/hooks/useEffect.jsx index 76ad1f11e..c9e95e38f 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/useEffect.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/useEffect.jsx @@ -149,7 +149,7 @@ export default function describeUseEffect({ }); describe('on componentDidUpdate & componentDidMount', () => { - const expectedCountString = x => `You clicked ${x} times`; + const expectedCountString = (x) => `You clicked ${x} times`; let setDocumentTitle; function ClickCounterPage() { diff --git a/packages/enzyme-test-suite/test/shared/hooks/useReducer.jsx b/packages/enzyme-test-suite/test/shared/hooks/useReducer.jsx index 6e0670858..987b584a9 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/useReducer.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/useReducer.jsx @@ -40,7 +40,7 @@ export default function describeUseReducer({
    - {state.map(text => ( + {state.map((text) => (

    {text}

    ))}
    diff --git a/packages/enzyme-test-suite/test/shared/methods/children.jsx b/packages/enzyme-test-suite/test/shared/methods/children.jsx index dc32de08d..7ef00f03b 100644 --- a/packages/enzyme-test-suite/test/shared/methods/children.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/children.jsx @@ -82,7 +82,7 @@ export default function describeChildren({ return (
    - {items.map(x => x)} + {items.map((x) => x)}
    ); } @@ -120,7 +120,7 @@ export default function describeChildren({ const Foo = ({ items }) => (
    - {items.map(x => x)} + {items.map((x) => x)}
    ); @@ -153,7 +153,7 @@ export default function describeChildren({ const wrapper = Wrap(); const children = wrapper.children(); - const textNodes = children.map(x => x.text()); + const textNodes = children.map((x) => x.text()); const expectedShallowNodes = ['Foo', ' Bar ', 'Foo', ' Bar ', 'Foo']; const expectedTextNodes = isShallow ? expectedShallowNodes : [expectedShallowNodes.join('')]; expect(textNodes).to.eql(expectedTextNodes); @@ -165,7 +165,7 @@ export default function describeChildren({ const { children } = this.props; const wrappedChildren = React.Children.map( children, - child => child && {child}, + (child) => child && {child}, ); const justifiedChildren = []; @@ -188,7 +188,7 @@ export default function describeChildren({ )); - expect(wrapper.children().map(x => x.debug())).to.eql([ + expect(wrapper.children().map((x) => x.debug())).to.eql([ `
    foo diff --git a/packages/enzyme-test-suite/test/shared/methods/everyWhere.jsx b/packages/enzyme-test-suite/test/shared/methods/everyWhere.jsx index f65dffbb7..2dee9d32f 100644 --- a/packages/enzyme-test-suite/test/shared/methods/everyWhere.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/everyWhere.jsx @@ -14,9 +14,9 @@ export default function describeEveryWhere({
    )); const foo = wrapper.find('.foo'); - expect(foo.everyWhere(n => n.hasClass('foo'))).to.equal(true); - expect(foo.everyWhere(n => n.hasClass('qoo'))).to.equal(false); - expect(foo.everyWhere(n => n.hasClass('bar'))).to.equal(false); + expect(foo.everyWhere((n) => n.hasClass('foo'))).to.equal(true); + expect(foo.everyWhere((n) => n.hasClass('qoo'))).to.equal(false); + expect(foo.everyWhere((n) => n.hasClass('bar'))).to.equal(false); }); }); } diff --git a/packages/enzyme-test-suite/test/shared/methods/findWhere.jsx b/packages/enzyme-test-suite/test/shared/methods/findWhere.jsx index 92e628bf4..a14ab2743 100644 --- a/packages/enzyme-test-suite/test/shared/methods/findWhere.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/findWhere.jsx @@ -96,12 +96,12 @@ export default function describeFindWhere({ const selector = 'blah'; const wrapper = Wrap(); - const foundSpan = wrapper.findWhere(n => ( + const foundSpan = wrapper.findWhere((n) => ( n.type() === 'span' && n.props()['data-foo'] === selector )); expect(foundSpan.type()).to.equal('span'); - const foundNotSpan = wrapper.findWhere(n => ( + const foundNotSpan = wrapper.findWhere((n) => ( n.type() !== 'span' && n.props()['data-foo'] === selector )); expect(foundNotSpan.type()).to.equal('i'); @@ -129,14 +129,14 @@ export default function describeFindWhere({ const selector = 'blah'; const wrapper = Wrap(); - const foundSpans = wrapper.findWhere(n => ( + const foundSpans = wrapper.findWhere((n) => ( n.type() === 'span' && n.props()['data-foo'] === selector )); expect(foundSpans).to.have.lengthOf(2); expect(foundSpans.get(0).type).to.equal('span'); expect(foundSpans.get(1).type).to.equal('span'); - const foundNotSpans = wrapper.findWhere(n => ( + const foundNotSpans = wrapper.findWhere((n) => ( n.type() !== 'span' && n.props()['data-foo'] === selector )); expect(foundNotSpans).to.have.lengthOf(2); @@ -160,12 +160,12 @@ export default function describeFindWhere({ const selector = 'blah'; const wrapper = Wrap(); - const foundSpan = wrapper.findWhere(n => ( + const foundSpan = wrapper.findWhere((n) => ( n.type() === 'span' && n.props()['data-foo'] === selector )); expect(foundSpan.type()).to.equal('span'); - const foundNotSpan = wrapper.findWhere(n => ( + const foundNotSpan = wrapper.findWhere((n) => ( n.type() !== 'span' && n.props()['data-foo'] === selector )); expect(foundNotSpan).to.have.lengthOf(0); @@ -193,7 +193,7 @@ export default function describeFindWhere({ const selector = 'blah'; const wrapper = Wrap(); - const foundSpan = wrapper.findWhere(n => ( + const foundSpan = wrapper.findWhere((n) => ( n.type() === 'span' && n.props()['data-foo'] === selector )); @@ -248,12 +248,12 @@ export default function describeFindWhere({ const selector = 'blah'; const wrapper = Wrap(); - const foundSpan = wrapper.findWhere(n => ( + const foundSpan = wrapper.findWhere((n) => ( n.type() === 'span' && n.props()['data-foo'] === selector )); expect(foundSpan.type()).to.equal('span'); - const foundNotSpan = wrapper.findWhere(n => ( + const foundNotSpan = wrapper.findWhere((n) => ( n.type() !== 'span' && n.props()['data-foo'] === selector )); expect(foundNotSpan.type()).to.equal('i'); @@ -271,12 +271,12 @@ export default function describeFindWhere({ const selector = 'blah'; const wrapper = Wrap(); - const foundSpan = wrapper.findWhere(n => ( + const foundSpan = wrapper.findWhere((n) => ( n.type() === 'span' && n.props()['data-foo'] === selector )); expect(foundSpan.type()).to.equal('span'); - const foundNotSpan = wrapper.findWhere(n => ( + const foundNotSpan = wrapper.findWhere((n) => ( n.type() !== 'span' && n.props()['data-foo'] === selector )); expect(foundNotSpan).to.have.lengthOf(0); @@ -349,7 +349,7 @@ export default function describeFindWhere({ const passedNodes = stub.getCalls().map(({ args: [firstArg] }) => firstArg); - const textContents = passedNodes.map(n => [n.debug(), n.text()]); + const textContents = passedNodes.map((n) => [n.debug(), n.text()]); const expected = [ [wrapper.debug(), 'foo bar'], // root ['
    ', ''], // first div @@ -372,8 +372,8 @@ export default function describeFindWhere({ wrapper.findWhere(stub); const passedNodes = stub.getCalls().map(({ args: [firstArg] }) => firstArg); - const getElement = n => (isShallow ? n.getElement() : n.getDOMNode()); - const hasElements = passedNodes.map(n => [n.debug(), getElement(n) && true]); + const getElement = (n) => (isShallow ? n.getElement() : n.getDOMNode()); + const hasElements = passedNodes.map((n) => [n.debug(), getElement(n) && true]); const expected = [ [wrapper.debug(), true], // root ['
    ', true], // first div @@ -414,7 +414,7 @@ export default function describeFindWhere({ const wrapper = Wrap(); - expect(wrapper.findWhere(node => node.type() === Portal)).to.have.lengthOf(1); + expect(wrapper.findWhere((node) => node.type() === Portal)).to.have.lengthOf(1); }); }); } diff --git a/packages/enzyme-test-suite/test/shared/methods/flatMap.jsx b/packages/enzyme-test-suite/test/shared/methods/flatMap.jsx index 0398cf5ba..855d8e0be 100644 --- a/packages/enzyme-test-suite/test/shared/methods/flatMap.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/flatMap.jsx @@ -23,7 +23,7 @@ export default function describeFlatMap({
    )); - const nodes = wrapper.find('.foo').flatMap(w => w.children().getElements()); + const nodes = wrapper.find('.foo').flatMap((w) => w.children().getElements()); expect(nodes).to.have.lengthOf(6); expect(nodes.at(0).hasClass('bar')).to.equal(true); diff --git a/packages/enzyme-test-suite/test/shared/methods/getWrappingComponent.jsx b/packages/enzyme-test-suite/test/shared/methods/getWrappingComponent.jsx index d19b08e59..ab390e266 100644 --- a/packages/enzyme-test-suite/test/shared/methods/getWrappingComponent.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/getWrappingComponent.jsx @@ -195,7 +195,7 @@ export default function describeGetWrappingComponent({ } const wrapper = Wrap(( - {value =>
    {value}
    } + {(value) =>
    {value}
    }
    ), { wrappingComponent: WrappingComponent, diff --git a/packages/enzyme-test-suite/test/shared/methods/invoke.jsx b/packages/enzyme-test-suite/test/shared/methods/invoke.jsx index 8ce6ec247..b033a6b37 100644 --- a/packages/enzyme-test-suite/test/shared/methods/invoke.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/invoke.jsx @@ -107,7 +107,7 @@ export default function describeInvoke({ [counter], ); return ( - + ); } const wrapper = Wrap(); diff --git a/packages/enzyme-test-suite/test/shared/methods/key.jsx b/packages/enzyme-test-suite/test/shared/methods/key.jsx index 1c40ceadb..b8dda3f68 100644 --- a/packages/enzyme-test-suite/test/shared/methods/key.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/key.jsx @@ -8,7 +8,7 @@ export default function describeKey({ it('returns the key of the node', () => { const wrapper = Wrap((
      - {['foo', 'bar', ''].map(s =>
    • {s}
    • )} + {['foo', 'bar', ''].map((s) =>
    • {s}
    • )}
    )).find('li'); expect(wrapper.at(0).key()).to.equal('foo'); diff --git a/packages/enzyme-test-suite/test/shared/methods/map.jsx b/packages/enzyme-test-suite/test/shared/methods/map.jsx index 2a13d7b2e..eb03fc9b3 100644 --- a/packages/enzyme-test-suite/test/shared/methods/map.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/map.jsx @@ -39,7 +39,7 @@ export default function describeMap({
    )); - const result = wrapper.find('.foo').map(w => w.props().className); + const result = wrapper.find('.foo').map((w) => w.props().className); expect(result).to.eql([ 'foo bax', diff --git a/packages/enzyme-test-suite/test/shared/methods/reduce.jsx b/packages/enzyme-test-suite/test/shared/methods/reduce.jsx index b813ee378..13af35cdc 100644 --- a/packages/enzyme-test-suite/test/shared/methods/reduce.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/reduce.jsx @@ -21,7 +21,7 @@ export default function describeReduce({
    )); - const spy = sinon.spy(n => n + 1); + const spy = sinon.spy((n) => n + 1); wrapper.find('.foo').reduce(spy, 0); diff --git a/packages/enzyme-test-suite/test/shared/methods/reduceRight.jsx b/packages/enzyme-test-suite/test/shared/methods/reduceRight.jsx index 383e0b235..f79a39e78 100644 --- a/packages/enzyme-test-suite/test/shared/methods/reduceRight.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/reduceRight.jsx @@ -21,7 +21,7 @@ export default function describeReduceRight({
    )); - const spy = sinon.spy(n => n + 1); + const spy = sinon.spy((n) => n + 1); wrapper.find('.foo').reduceRight(spy, 0); diff --git a/packages/enzyme-test-suite/test/shared/methods/renderProp.jsx b/packages/enzyme-test-suite/test/shared/methods/renderProp.jsx index 7006accd2..71a9df3b3 100644 --- a/packages/enzyme-test-suite/test/shared/methods/renderProp.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/renderProp.jsx @@ -97,7 +97,7 @@ export default function describeRenderProp({ describeIf(is('>= 16'), 'allows non-nodes', () => { function MyComponent({ val }) { - return x} />; + return x} />; } function ComponentWithRenderProp({ val, r }) { diff --git a/packages/enzyme-test-suite/test/shared/methods/setProps.jsx b/packages/enzyme-test-suite/test/shared/methods/setProps.jsx index 6a5d855bd..e009547dc 100644 --- a/packages/enzyme-test-suite/test/shared/methods/setProps.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/setProps.jsx @@ -525,7 +525,7 @@ export default function describeSetProps({ }); it('merges newProps with oldProps', () => { - const RendersBarSFC = props => ( + const RendersBarSFC = (props) => ( ); const BarSFC = () => ( diff --git a/packages/enzyme-test-suite/test/shared/methods/someWhere.jsx b/packages/enzyme-test-suite/test/shared/methods/someWhere.jsx index 48207c1c2..f87105600 100644 --- a/packages/enzyme-test-suite/test/shared/methods/someWhere.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/someWhere.jsx @@ -14,9 +14,9 @@ export default function describeSomeWhere({
    )); const foo = wrapper.find('.foo'); - expect(foo.someWhere(n => n.hasClass('qoo'))).to.equal(true); - expect(foo.someWhere(n => n.hasClass('foo'))).to.equal(true); - expect(foo.someWhere(n => n.hasClass('bar'))).to.equal(false); + expect(foo.someWhere((n) => n.hasClass('qoo'))).to.equal(true); + expect(foo.someWhere((n) => n.hasClass('foo'))).to.equal(true); + expect(foo.someWhere((n) => n.hasClass('bar'))).to.equal(false); }); }); } diff --git a/packages/enzyme-test-suite/test/shared/methods/text.jsx b/packages/enzyme-test-suite/test/shared/methods/text.jsx index 731a71e27..8fe1bfe36 100644 --- a/packages/enzyme-test-suite/test/shared/methods/text.jsx +++ b/packages/enzyme-test-suite/test/shared/methods/text.jsx @@ -38,7 +38,7 @@ export default function describeText({ const { items } = this.props; return (
    - {items.map(x => x)} + {items.map((x) => x)}
    ); } @@ -120,7 +120,7 @@ export default function describeText({ } } const wrapper = Wrap(); - const charCodes = wrapper.text().split('').map(x => x.charCodeAt(0)); + const charCodes = wrapper.text().split('').map((x) => x.charCodeAt(0)); expect(charCodes).to.eql([ 0x00a0, // non-breaking space 0x20, // normal space @@ -132,7 +132,7 @@ export default function describeText({ it('handles nodes with mapped children', () => { const Foo = ({ items }) => (
    - {items.map(x => x)} + {items.map((x) => x)}
    ); matchesRender(); diff --git a/packages/enzyme/.eslintrc b/packages/enzyme/.eslintrc index d639d726a..590d2dd1a 100644 --- a/packages/enzyme/.eslintrc +++ b/packages/enzyme/.eslintrc @@ -7,6 +7,7 @@ }, "rules": { "id-length": 0, + "max-classes-per-file": 0, "new-cap": [2, { "capIsNewExceptions": ["AND"] }], "react/jsx-pascal-case": [2, { "allowAllCaps": true }], "react/no-find-dom-node": 1, diff --git a/packages/enzyme/package.json b/packages/enzyme/package.json index ce8f3f0c4..7a3dc4e2a 100644 --- a/packages/enzyme/package.json +++ b/packages/enzyme/package.json @@ -62,14 +62,14 @@ "babel-cli": "^6.26.0", "babel-plugin-transform-replace-object-assign": "^1.0.0", "babel-preset-airbnb": "^2.6.0", - "eslint": "^5.16.0", - "eslint-config-airbnb": "^17.1.1", + "eslint": "^6.3.0", + "eslint-config-airbnb": "^18.0.1", "eslint-plugin-import": "^2.18.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react": "^7.14.3", "in-publish": "^2.0.0", "jsdom": "^6.5.1", - "rimraf": "^2.6.3", - "safe-publish-latest": "^1.1.2" + "rimraf": "^2.7.1", + "safe-publish-latest": "^1.1.3" } } diff --git a/packages/enzyme/src/Debug.js b/packages/enzyme/src/Debug.js index da33c6a77..6f47792e5 100644 --- a/packages/enzyme/src/Debug.js +++ b/packages/enzyme/src/Debug.js @@ -30,7 +30,7 @@ export function spaces(n) { } export function indent(depth, string) { - return string.split('\n').map(x => `${spaces(depth)}${x}`).join('\n'); + return string.split('\n').map((x) => `${spaces(depth)}${x}`).join('\n'); } function propString(prop, options) { @@ -58,13 +58,13 @@ function propString(prop, options) { function propsString(node, options) { const props = propsOfNode(node); - const keys = Object.keys(props).filter(x => x !== 'children'); - return keys.map(key => `${key}=${propString(props[key], options)}`).join(' '); + const keys = Object.keys(props).filter((x) => x !== 'children'); + return keys.map((key) => `${key}=${propString(props[key], options)}`).join(' '); } function indentChildren(childrenStrs, indentLength) { return childrenStrs.length - ? `\n${childrenStrs.map(x => indent(indentLength, x)).join('\n')}\n` + ? `\n${childrenStrs.map((x) => indent(indentLength, x)).join('\n')}\n` : ''; } @@ -92,7 +92,7 @@ export function debugNode(node, indentLength = 2, options = {}) { } const childrenStrs = childrenOfNode(node) - .map(n => debugNode(n, indentLength, options)) + .map((n) => debugNode(n, indentLength, options)) .filter(Boolean); const type = typeName(node); @@ -107,5 +107,5 @@ export function debugNode(node, indentLength = 2, options = {}) { } export function debugNodes(nodes, options = {}) { - return nodes.map(node => debugNode(node, undefined, options)).join('\n\n\n'); + return nodes.map((node) => debugNode(node, undefined, options)).join('\n\n\n'); } diff --git a/packages/enzyme/src/RSTTraversal.js b/packages/enzyme/src/RSTTraversal.js index 52c1f29e9..318ed0a11 100644 --- a/packages/enzyme/src/RSTTraversal.js +++ b/packages/enzyme/src/RSTTraversal.js @@ -43,7 +43,7 @@ export function treeForEach(tree, fn) { if (tree) { fn(tree); } - childrenOfNode(tree).forEach(node => treeForEach(node, fn)); + childrenOfNode(tree).forEach((node) => treeForEach(node, fn)); } export function treeFilter(tree, fn) { @@ -81,14 +81,14 @@ export function findParentNode(root, targetNode) { } function pathFilter(path, fn) { - return path.filter(tree => treeFilter(tree, fn).length !== 0); + return path.filter((tree) => treeFilter(tree, fn).length !== 0); } export function pathToNode(node, root) { const queue = [root]; const path = []; - const hasNode = testNode => node === testNode; + const hasNode = (testNode) => node === testNode; while (queue.length) { const current = queue.pop(); diff --git a/packages/enzyme/src/ReactWrapper.js b/packages/enzyme/src/ReactWrapper.js index 2bee4730a..16980eecd 100644 --- a/packages/enzyme/src/ReactWrapper.js +++ b/packages/enzyme/src/ReactWrapper.js @@ -51,7 +51,7 @@ const UPDATED_BY = sym('__updatedBy__'); * @returns {ReactWrapper} */ function findWhereUnwrapped(wrapper, predicate, filter = treeFilter) { - return wrapper.flatMap(n => filter(n.getNodeInternal(), predicate)); + return wrapper.flatMap((n) => filter(n.getNodeInternal(), predicate)); } /** @@ -186,7 +186,7 @@ class ReactWrapper { * @return {Array} */ getElements() { - return this[NODES].map(n => getAdapter(this[OPTIONS]).nodeToElement(n)); + return this[NODES].map((n) => getAdapter(this[OPTIONS]).nodeToElement(n)); } // eslint-disable-next-line class-methods-use-this @@ -208,7 +208,7 @@ class ReactWrapper { */ getDOMNode() { const adapter = getAdapter(this[OPTIONS]); - return this.single('getDOMNode', n => adapter.nodeToHostNode(n, true)); + return this.single('getDOMNode', (n) => adapter.nodeToHostNode(n, true)); } /** @@ -425,12 +425,12 @@ class ReactWrapper { const adapter = getAdapter(this[OPTIONS]); const predicate = Array.isArray(nodeOrNodes) - ? other => containsChildrenSubArray( + ? (other) => containsChildrenSubArray( nodeEqual, other, - nodeOrNodes.map(node => adapter.elementToNode(node)), + nodeOrNodes.map((node) => adapter.elementToNode(node)), ) - : other => nodeEqual(adapter.elementToNode(nodeOrNodes), other); + : (other) => nodeEqual(adapter.elementToNode(nodeOrNodes), other); return findWhereUnwrapped(this, predicate).length > 0; } @@ -453,7 +453,7 @@ class ReactWrapper { */ containsMatchingElement(node) { const rstNode = getAdapter(this[OPTIONS]).elementToNode(node); - const predicate = other => nodeMatches(rstNode, other, (a, b) => a <= b); + const predicate = (other) => nodeMatches(rstNode, other, (a, b) => a <= b); return findWhereUnwrapped(this, predicate).length > 0; } @@ -480,7 +480,7 @@ class ReactWrapper { throw new TypeError('nodes should be an Array'); } - return nodes.every(node => this.containsMatchingElement(node)); + return nodes.every((node) => this.containsMatchingElement(node)); } /** @@ -502,7 +502,7 @@ class ReactWrapper { * @returns {Boolean} */ containsAnyMatchingElements(nodes) { - return Array.isArray(nodes) && nodes.some(node => this.containsMatchingElement(node)); + return Array.isArray(nodes) && nodes.some((node) => this.containsMatchingElement(node)); } /** @@ -566,7 +566,7 @@ class ReactWrapper { */ is(selector) { const predicate = buildPredicate(selector); - return this.single('is', n => predicate(n)); + return this.single('is', (n) => predicate(n)); } /** @@ -588,7 +588,7 @@ class ReactWrapper { * @returns {ReactWrapper} */ filterWhere(predicate) { - return filterWhereUnwrapped(this, n => predicate(this.wrap(n))); + return filterWhereUnwrapped(this, (n) => predicate(this.wrap(n))); } /** @@ -612,7 +612,7 @@ class ReactWrapper { */ not(selector) { const predicate = buildPredicate(selector); - return filterWhereUnwrapped(this, n => !predicate(n)); + return filterWhereUnwrapped(this, (n) => !predicate(n)); } /** @@ -626,7 +626,7 @@ class ReactWrapper { */ text() { const adapter = getAdapter(this[OPTIONS]); - return this.single('text', n => getTextFromHostNodes(n, adapter)); + return this.single('text', (n) => getTextFromHostNodes(n, adapter)); } /** @@ -638,7 +638,7 @@ class ReactWrapper { */ html() { const adapter = getAdapter(this[OPTIONS]); - return this.single('html', n => getHTMLFromHostNodes(n, adapter)); + return this.single('html', (n) => getHTMLFromHostNodes(n, adapter)); } /** @@ -765,7 +765,7 @@ class ReactWrapper { * @returns {ReactWrapper} */ children(selector) { - const allChildren = this.flatMap(n => childrenOfNode(n.getNodeInternal()).filter(x => typeof x === 'object')); + const allChildren = this.flatMap((n) => childrenOfNode(n.getNodeInternal()).filter((x) => typeof x === 'object')); return selector ? allChildren.filter(selector) : allChildren; } @@ -801,7 +801,7 @@ class ReactWrapper { * @returns {ReactWrapper} */ parent() { - return this.flatMap(n => [n.parents().get(0)]); + return this.flatMap((n) => [n.parents().get(0)]); } /** @@ -892,7 +892,7 @@ class ReactWrapper { * @returns {String} */ key() { - return this.single('key', n => (n.key === undefined ? null : n.key)); + return this.single('key', (n) => (n.key === undefined ? null : n.key)); } /** @@ -902,7 +902,7 @@ class ReactWrapper { * @returns {String|Function} */ type() { - return this.single('type', n => typeOfNode(n)); + return this.single('type', (n) => typeOfNode(n)); } /** @@ -914,7 +914,7 @@ class ReactWrapper { */ name() { const adapter = getAdapter(this[OPTIONS]); - return this.single('name', n => ( + return this.single('name', (n) => ( adapter.displayNameOfNode ? adapter.displayNameOfNode(n) : displayNameOfNode(n) )); } @@ -932,7 +932,7 @@ class ReactWrapper { // eslint-disable-next-line no-console console.warn('It looks like you\'re calling `ReactWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector.'); } - return this.single('hasClass', n => hasClassName(n, className)); + return this.single('hasClass', (n) => hasClassName(n, className)); } /** @@ -1233,7 +1233,7 @@ class ReactWrapper { * (actually rendered HTML elements) ignoring the React nodes. */ hostNodes() { - return this.filterWhere(n => typeof n.type() === 'string'); + return this.filterWhere((n) => typeof n.type() === 'string'); } } diff --git a/packages/enzyme/src/ShallowWrapper.js b/packages/enzyme/src/ShallowWrapper.js index fc88d1521..7776ec10b 100644 --- a/packages/enzyme/src/ShallowWrapper.js +++ b/packages/enzyme/src/ShallowWrapper.js @@ -57,7 +57,7 @@ const PROVIDER_VALUES = sym('__providerValues__'); * @returns {ShallowWrapper} */ function findWhereUnwrapped(wrapper, predicate, filter = treeFilter) { - return wrapper.flatMap(n => filter(n.getNodeInternal(), predicate)); + return wrapper.flatMap((n) => filter(n.getNodeInternal(), predicate)); } /** @@ -266,7 +266,7 @@ function mockSCUIfgDSFPReturnNonNull(node, state) { const { restore } = spyMethod( instance, 'shouldComponentUpdate', - originalSCU => function shouldComponentUpdate(...args) { + (originalSCU) => function shouldComponentUpdate(...args) { instance.state = state; const sCUResult = originalSCU.apply(instance, args); const [, nextState] = args; @@ -471,7 +471,7 @@ class ShallowWrapper { * @return {ReactElement} */ getElement() { - return this.single('getElement', n => getAdapter(this[OPTIONS]).nodeToElement(n)); + return this.single('getElement', (n) => getAdapter(this[OPTIONS]).nodeToElement(n)); } /** @@ -480,7 +480,7 @@ class ShallowWrapper { * @return {Array} */ getElements() { - return this.getNodesInternal().map(n => getAdapter(this[OPTIONS]).nodeToElement(n)); + return this.getNodesInternal().map((n) => getAdapter(this[OPTIONS]).nodeToElement(n)); } // eslint-disable-next-line class-methods-use-this @@ -871,12 +871,12 @@ class ShallowWrapper { throw new Error('ShallowWrapper::contains() can only be called with a ReactElement (or an array of them), a string, or a number as an argument.'); } const predicate = Array.isArray(nodeOrNodes) - ? other => containsChildrenSubArray( + ? (other) => containsChildrenSubArray( nodeEqual, other, - nodeOrNodes.map(node => adapter.elementToNode(node)), + nodeOrNodes.map((node) => adapter.elementToNode(node)), ) - : other => nodeEqual(adapter.elementToNode(nodeOrNodes), other); + : (other) => nodeEqual(adapter.elementToNode(nodeOrNodes), other); return findWhereUnwrapped(this, predicate).length > 0; } @@ -901,7 +901,7 @@ class ShallowWrapper { containsMatchingElement(node) { const adapter = getAdapter(this[OPTIONS]); const rstNode = adapter.elementToNode(node); - const predicate = other => nodeMatches(rstNode, other, (a, b) => a <= b); + const predicate = (other) => nodeMatches(rstNode, other, (a, b) => a <= b); return findWhereUnwrapped(this, predicate).length > 0; } @@ -929,7 +929,7 @@ class ShallowWrapper { throw new TypeError('nodes should be an Array'); } - return nodes.every(node => this.containsMatchingElement(node)); + return nodes.every((node) => this.containsMatchingElement(node)); } /** @@ -952,7 +952,7 @@ class ShallowWrapper { * @returns {Boolean} */ containsAnyMatchingElements(nodes) { - return Array.isArray(nodes) && nodes.some(node => this.containsMatchingElement(node)); + return Array.isArray(nodes) && nodes.some((node) => this.containsMatchingElement(node)); } /** @@ -1016,7 +1016,7 @@ class ShallowWrapper { */ is(selector) { const predicate = buildPredicate(selector); - return this.single('is', n => predicate(n)); + return this.single('is', (n) => predicate(n)); } /** @@ -1027,7 +1027,7 @@ class ShallowWrapper { isEmptyRender() { const nodes = this.getNodesInternal(); - return nodes.every(n => isEmptyValue(n)); + return nodes.every((n) => isEmptyValue(n)); } /** @@ -1039,7 +1039,7 @@ class ShallowWrapper { * @returns {ShallowWrapper} */ filterWhere(predicate) { - return filterWhereUnwrapped(this, n => predicate(this.wrap(n))); + return filterWhereUnwrapped(this, (n) => predicate(this.wrap(n))); } /** @@ -1063,7 +1063,7 @@ class ShallowWrapper { */ not(selector) { const predicate = buildPredicate(selector); - return filterWhereUnwrapped(this, n => !predicate(n)); + return filterWhereUnwrapped(this, (n) => !predicate(n)); } /** @@ -1219,7 +1219,7 @@ class ShallowWrapper { * @returns {ShallowWrapper} */ children(selector) { - const allChildren = this.flatMap(n => childrenOfNode(n.getNodeInternal())); + const allChildren = this.flatMap((n) => childrenOfNode(n.getNodeInternal())); return selector ? allChildren.filter(selector) : allChildren; } @@ -1255,7 +1255,7 @@ class ShallowWrapper { * @returns {ShallowWrapper} */ parent() { - return this.flatMap(n => [n.parents().get(0)]); + return this.flatMap((n) => [n.parents().get(0)]); } /** @@ -1280,7 +1280,7 @@ class ShallowWrapper { * @returns {ShallowWrapper} */ shallow(options) { - return this.single('shallow', n => ( + return this.single('shallow', (n) => ( this.wrap(getAdapter(this[OPTIONS]).nodeToElement(n), null, options) )); } @@ -1358,7 +1358,7 @@ class ShallowWrapper { * @returns {String} */ key() { - return this.single('key', n => (n.key === undefined ? null : n.key)); + return this.single('key', (n) => (n.key === undefined ? null : n.key)); } /** @@ -1369,7 +1369,7 @@ class ShallowWrapper { * @returns {String|Function|null} */ type() { - return this.single('type', n => typeOfNode(n)); + return this.single('type', (n) => typeOfNode(n)); } /** @@ -1381,7 +1381,7 @@ class ShallowWrapper { */ name() { const adapter = getAdapter(this[OPTIONS]); - return this.single('name', n => ( + return this.single('name', (n) => ( adapter.displayNameOfNode ? adapter.displayNameOfNode(n) : displayNameOfNode(n) )); } @@ -1399,7 +1399,7 @@ class ShallowWrapper { // eslint-disable-next-line no-console console.warn('It looks like you\'re calling `ShallowWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector.'); } - return this.single('hasClass', n => hasClassName(n, className)); + return this.single('hasClass', (n) => hasClassName(n, className)); } /** @@ -1713,7 +1713,7 @@ class ShallowWrapper { * (actually rendered HTML elements) ignoring the React nodes. */ hostNodes() { - return this.filterWhere(n => typeof n.type() === 'string'); + return this.filterWhere((n) => typeof n.type() === 'string'); } } diff --git a/packages/enzyme/src/Utils.js b/packages/enzyme/src/Utils.js index 14e198f99..935c069d3 100644 --- a/packages/enzyme/src/Utils.js +++ b/packages/enzyme/src/Utils.js @@ -224,7 +224,7 @@ export function childrenToSimplifiedArray(nodeChildren, isLoose = false) { } if (isLoose) { - return simplifiedArray.map(x => (typeof x === 'string' ? trim(x) : x)); + return simplifiedArray.map((x) => (typeof x === 'string' ? trim(x) : x)); } return simplifiedArray; @@ -259,7 +259,7 @@ export function withSetStateAllowed(fn) { export function AND(fns) { const fnsReversed = fns.slice().reverse(); - return x => fnsReversed.every(fn => fn(x)); + return (x) => fnsReversed.every((fn) => fn(x)); } export function displayNameOfNode(node) { diff --git a/packages/enzyme/src/selectors.js b/packages/enzyme/src/selectors.js index d8479c270..5f3e5f97d 100644 --- a/packages/enzyme/src/selectors.js +++ b/packages/enzyme/src/selectors.js @@ -148,10 +148,10 @@ function matchPseudoSelector(node, token, root) { const { name, parameters } = token; if (name === 'not') { // eslint-disable-next-line no-use-before-define - return parameters.every(selector => reduceTreeBySelector(selector, node).length === 0); + return parameters.every((selector) => reduceTreeBySelector(selector, node).length === 0); } if (name === 'empty') { - return treeFilter(node, n => n !== node).length === 0; + return treeFilter(node, (n) => n !== node).length === 0; } if (name === 'first-child') { const { rendered } = findParentNode(root, node); @@ -238,7 +238,7 @@ function nodeMatchesToken(node, token, root) { * @param {Token} token */ function buildPredicateFromToken(token, root) { - return node => token.body.every(bodyToken => nodeMatchesToken(node, bodyToken, root)); + return (node) => token.body.every((bodyToken) => nodeMatchesToken(node, bodyToken, root)); } /** @@ -247,7 +247,7 @@ function buildPredicateFromToken(token, root) { * @param {Array} tokens */ function isComplexSelector(tokens) { - return tokens.some(token => token.type !== SELECTOR); + return tokens.some((token) => token.type !== SELECTOR); } @@ -274,16 +274,16 @@ export function buildPredicate(selector) { ? adapter.isValidElementType(selector) : typeof selector === 'function'; if (isElementType) { - return node => adapter.matchesElementType(node, selector); + return (node) => adapter.matchesElementType(node, selector); } // If the selector is an non-empty object, treat the keys/values as props if (typeof selector === 'object') { if (!Array.isArray(selector) && selector !== null && Object.keys(selector).length > 0) { - const hasUndefinedValues = values(selector).some(value => typeof value === 'undefined'); + const hasUndefinedValues = values(selector).some((value) => typeof value === 'undefined'); if (hasUndefinedValues) { throw new TypeError('Enzyme::Props can’t have `undefined` values. Try using ‘findWhere()’ instead.'); } - return node => nodeMatchesObjectProps(node, selector); + return (node) => nodeMatchesObjectProps(node, selector); } throw new TypeError('Enzyme::Selector does not support an array, null, or empty object as a selector'); } @@ -378,7 +378,7 @@ export function reduceTreeBySelector(selector, root) { if (typeof selector !== 'string') { const elements = elementsByConstructor(selector); if (elements.length > 0) { - return flat(elements.map(x => reduceTreeBySelector(x.tag, root))); + return flat(elements.map((x) => reduceTreeBySelector(x.tag, root))); // when https://github.com/aweary/rst-selector-parser/issues/15 is resolved // const htmlTagNames = elements.map(x => x.tag).join(', '); @@ -454,6 +454,6 @@ export function reduceTreeBySelector(selector, root) { } export function reduceTreesBySelector(selector, roots) { - const results = roots.map(n => reduceTreeBySelector(selector, n)); + const results = roots.map((n) => reduceTreeBySelector(selector, n)); return unique(flat(results, 1)); } diff --git a/since.js b/since.js index a6cbea55e..07380a02c 100644 --- a/since.js +++ b/since.js @@ -9,8 +9,8 @@ const packagesDir = path.join(__dirname, 'packages'); const docsDir = path.join(__dirname, 'docs'); const packages = (process.argv.length > 2 ? [process.argv[2]] : glob.sync('*', { cwd: packagesDir })) - .map(name => JSON.parse(fs.readFileSync(path.join(packagesDir, name, 'package.json')))) - .filter(x => !x.private && x.name !== 'enzyme-example-mocha'); + .map((name) => JSON.parse(fs.readFileSync(path.join(packagesDir, name, 'package.json')))) + .filter((x) => !x.private && x.name !== 'enzyme-example-mocha'); packages.forEach((pkg) => { const tag = `${pkg.name === 'docs' ? 'enzyme' : pkg.name}@${pkg.version}`;