From 0c048f0646754de103cc2d9825762340bed06119 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Tue, 6 Nov 2018 21:33:33 +0000 Subject: [PATCH] Use Prettier (#1071) * Use Prettier * Make sure linting and formatting are part of the testing process. * Run prettier on existing code. --- .eslintrc | 3 +- .prettierrc | 4 + .travis.yml | 3 +- package-lock.json | 45 +++++++++++ package.json | 5 ++ src/components/connectAdvanced.js | 4 +- src/connect/connect.js | 24 ++++-- src/connect/mapDispatchToProps.js | 10 ++- src/connect/mapStateToProps.js | 11 +-- src/connect/mergeProps.js | 15 ++-- src/connect/selectorFactory.js | 17 +++-- src/connect/verifySubselectors.js | 13 +++- src/connect/wrapMapToProps.js | 26 ++++--- src/utils/shallowEqual.js | 11 ++- test/babel-transformer.jest.js | 2 +- test/install-test-deps.js | 46 ++++++----- test/run-tests.js | 6 +- test/utils/shallowEqual.spec.js | 105 ++++++++------------------ test/utils/wrapActionCreators.spec.js | 2 - 19 files changed, 199 insertions(+), 153 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index 05527f778..a6df1adf7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,8 @@ "extends": [ "eslint:recommended", "plugin:import/recommended", - "plugin:react/recommended" + "plugin:react/recommended", + "plugin:prettier/recommended" ], "parserOptions": { "ecmaVersion": 6, diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..b2095be81 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "semi": false, + "singleQuote": true +} diff --git a/.travis.yml b/.travis.yml index e4df5ceca..225b3efe5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ env: - REACT=16.6 sudo: false script: - - npm run lint - - npm run test + - npm test after_success: - npm run coverage diff --git a/package-lock.json b/package-lock.json index f5f825a12..7044d1d9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4129,6 +4129,15 @@ } } }, + "eslint-config-prettier": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-3.1.0.tgz", + "integrity": "sha512-QYGfmzuc4q4J6XIhlp8vRKdI/fI0tQfQPy1dME3UOLprE+v4ssH/3W9LM2Q7h5qBcy5m0ehCrBDU2YF8q6OY8w==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + } + }, "eslint-import-resolver-node": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz", @@ -4190,6 +4199,15 @@ } } }, + "eslint-plugin-prettier": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.0.tgz", + "integrity": "sha512-4g11opzhqq/8+AMmo5Vc2Gn7z9alZ4JqrbZ+D4i8KlSyxeQhZHlmIrY8U9Akf514MoEhogPa87Jgkq87aZ2Ohw==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-plugin-react": { "version": "7.9.1", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.9.1.tgz", @@ -4440,6 +4458,12 @@ "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -5160,6 +5184,12 @@ "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", "dev": true }, + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", @@ -8204,6 +8234,21 @@ "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=", "dev": true }, + "prettier": { + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.14.3.tgz", + "integrity": "sha512-qZDVnCrnpsRJJq5nSsiHCE3BYMED2OtsI+cmzIzF1QIfqm5ALf8tEJcO27zV1gKNKRPdhjO0dNWnrzssDQ1tFg==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-format": { "version": "23.2.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-23.2.0.tgz", diff --git a/package.json b/package.json index fbd0d7020..ee1218dd5 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,10 @@ "build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js", "build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min", "clean": "rimraf lib dist es coverage", + "format": "prettier --write '{src,test}/**/*.js'", "lint": "eslint src test/utils test/components", "prepare": "npm run clean && npm run build", + "pretest": "npm run lint", "test": "node ./test/run-tests.js", "coverage": "codecov" }, @@ -68,12 +70,15 @@ "cross-spawn": "^6.0.5", "es3ify": "^0.2.0", "eslint": "^4.19.1", + "eslint-config-prettier": "^3.1.0", "eslint-plugin-import": "^2.12.0", + "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-react": "^7.9.1", "glob": "^7.1.1", "jest": "^23.6.0", "jest-dom": "^1.12.0", "npm-run": "^5.0.1", + "prettier": "1.14.3", "react": "^16.6.0", "react-dom": "^16.6.0", "react-testing-library": "^5.0.0", diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index eec203d2c..fee9776df 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -86,8 +86,8 @@ export default function connectAdvanced( invariant( isValidElementType(WrappedComponent), `You must pass a component to the function returned by ` + - `${methodName}. Instead received ${JSON.stringify(WrappedComponent)}` - ); + `${methodName}. Instead received ${JSON.stringify(WrappedComponent)}` + ) } const wrappedComponentName = diff --git a/src/connect/connect.js b/src/connect/connect.js index e4dbf82dc..d255c17d8 100644 --- a/src/connect/connect.js +++ b/src/connect/connect.js @@ -29,11 +29,17 @@ function match(arg, factories, name) { } return (dispatch, options) => { - throw new Error(`Invalid value of type ${typeof arg} for ${name} argument when connecting component ${options.wrappedComponentName}.`) + throw new Error( + `Invalid value of type ${typeof arg} for ${name} argument when connecting component ${ + options.wrappedComponentName + }.` + ) } } -function strictEqual(a, b) { return a === b } +function strictEqual(a, b) { + return a === b +} // createConnect with default args builds the 'official' connect behavior. Calling it with // different options opens up some testing and extensibility scenarios @@ -57,15 +63,23 @@ export function createConnect({ ...extraOptions } = {} ) { - const initMapStateToProps = match(mapStateToProps, mapStateToPropsFactories, 'mapStateToProps') - const initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories, 'mapDispatchToProps') + const initMapStateToProps = match( + mapStateToProps, + mapStateToPropsFactories, + 'mapStateToProps' + ) + const initMapDispatchToProps = match( + mapDispatchToProps, + mapDispatchToPropsFactories, + 'mapDispatchToProps' + ) const initMergeProps = match(mergeProps, mergePropsFactories, 'mergeProps') return connectHOC(selectorFactory, { // used in error messages methodName: 'connect', - // used to compute Connect's displayName from the wrapped component's displayName. + // used to compute Connect's displayName from the wrapped component's displayName. getDisplayName: name => `Connect(${name})`, // if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changes diff --git a/src/connect/mapDispatchToProps.js b/src/connect/mapDispatchToProps.js index 405004538..f352e1985 100644 --- a/src/connect/mapDispatchToProps.js +++ b/src/connect/mapDispatchToProps.js @@ -2,20 +2,22 @@ import { bindActionCreators } from 'redux' import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps' export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) { - return (typeof mapDispatchToProps === 'function') + return typeof mapDispatchToProps === 'function' ? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') : undefined } export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) { - return (!mapDispatchToProps) + return !mapDispatchToProps ? wrapMapToPropsConstant(dispatch => ({ dispatch })) : undefined } export function whenMapDispatchToPropsIsObject(mapDispatchToProps) { - return (mapDispatchToProps && typeof mapDispatchToProps === 'object') - ? wrapMapToPropsConstant(dispatch => bindActionCreators(mapDispatchToProps, dispatch)) + return mapDispatchToProps && typeof mapDispatchToProps === 'object' + ? wrapMapToPropsConstant(dispatch => + bindActionCreators(mapDispatchToProps, dispatch) + ) : undefined } diff --git a/src/connect/mapStateToProps.js b/src/connect/mapStateToProps.js index 039291b0a..6bfc0b368 100644 --- a/src/connect/mapStateToProps.js +++ b/src/connect/mapStateToProps.js @@ -1,18 +1,13 @@ import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps' export function whenMapStateToPropsIsFunction(mapStateToProps) { - return (typeof mapStateToProps === 'function') + return typeof mapStateToProps === 'function' ? wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') : undefined } export function whenMapStateToPropsIsMissing(mapStateToProps) { - return (!mapStateToProps) - ? wrapMapToPropsConstant(() => ({})) - : undefined + return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : undefined } -export default [ - whenMapStateToPropsIsFunction, - whenMapStateToPropsIsMissing -] +export default [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing] diff --git a/src/connect/mergeProps.js b/src/connect/mergeProps.js index 9ef1c8ee5..ca21ea0a6 100644 --- a/src/connect/mergeProps.js +++ b/src/connect/mergeProps.js @@ -6,7 +6,8 @@ export function defaultMergeProps(stateProps, dispatchProps, ownProps) { export function wrapMergePropsFunc(mergeProps) { return function initMergePropsProxy( - dispatch, { displayName, pure, areMergedPropsEqual } + dispatch, + { displayName, pure, areMergedPropsEqual } ) { let hasRunOnce = false let mergedProps @@ -17,7 +18,6 @@ export function wrapMergePropsFunc(mergeProps) { if (hasRunOnce) { if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps - } else { hasRunOnce = true mergedProps = nextMergedProps @@ -32,18 +32,13 @@ export function wrapMergePropsFunc(mergeProps) { } export function whenMergePropsIsFunction(mergeProps) { - return (typeof mergeProps === 'function') + return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined } export function whenMergePropsIsOmitted(mergeProps) { - return (!mergeProps) - ? () => defaultMergeProps - : undefined + return !mergeProps ? () => defaultMergeProps : undefined } -export default [ - whenMergePropsIsFunction, - whenMergePropsIsOmitted -] +export default [whenMergePropsIsFunction, whenMergePropsIsOmitted] diff --git a/src/connect/selectorFactory.js b/src/connect/selectorFactory.js index de34b3361..db406766d 100644 --- a/src/connect/selectorFactory.js +++ b/src/connect/selectorFactory.js @@ -97,18 +97,21 @@ export function pureFinalPropsSelectorFactory( // props have not changed. If false, the selector will always return a new // object and shouldComponentUpdate will always return true. -export default function finalPropsSelectorFactory(dispatch, { - initMapStateToProps, - initMapDispatchToProps, - initMergeProps, - ...options -}) { +export default function finalPropsSelectorFactory( + dispatch, + { initMapStateToProps, initMapDispatchToProps, initMergeProps, ...options } +) { const mapStateToProps = initMapStateToProps(dispatch, options) const mapDispatchToProps = initMapDispatchToProps(dispatch, options) const mergeProps = initMergeProps(dispatch, options) if (process.env.NODE_ENV !== 'production') { - verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName) + verifySubselectors( + mapStateToProps, + mapDispatchToProps, + mergeProps, + options.displayName + ) } const selectorFactory = options.pure diff --git a/src/connect/verifySubselectors.js b/src/connect/verifySubselectors.js index 7c6b248b8..27444749a 100644 --- a/src/connect/verifySubselectors.js +++ b/src/connect/verifySubselectors.js @@ -3,8 +3,10 @@ import warning from '../utils/warning' function verify(selector, methodName, displayName) { if (!selector) { throw new Error(`Unexpected value for ${methodName} in ${displayName}.`) - - } else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') { + } else if ( + methodName === 'mapStateToProps' || + methodName === 'mapDispatchToProps' + ) { if (!selector.hasOwnProperty('dependsOnOwnProps')) { warning( `The selector for ${methodName} of ${displayName} did not specify a value for dependsOnOwnProps.` @@ -13,7 +15,12 @@ function verify(selector, methodName, displayName) { } } -export default function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) { +export default function verifySubselectors( + mapStateToProps, + mapDispatchToProps, + mergeProps, + displayName +) { verify(mapStateToProps, 'mapStateToProps', displayName) verify(mapDispatchToProps, 'mapDispatchToProps', displayName) verify(mergeProps, 'mergeProps', displayName) diff --git a/src/connect/wrapMapToProps.js b/src/connect/wrapMapToProps.js index 6b39c7961..53ff341ff 100644 --- a/src/connect/wrapMapToProps.js +++ b/src/connect/wrapMapToProps.js @@ -4,8 +4,10 @@ export function wrapMapToPropsConstant(getConstant) { return function initConstantSelector(dispatch, options) { const constant = getConstant(dispatch, options) - function constantSelector() { return constant } - constantSelector.dependsOnOwnProps = false + function constantSelector() { + return constant + } + constantSelector.dependsOnOwnProps = false return constantSelector } } @@ -13,28 +15,29 @@ export function wrapMapToPropsConstant(getConstant) { // dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args // to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine // whether mapToProps needs to be invoked when props have changed. -// +// // A length of one signals that mapToProps does not depend on props from the parent component. // A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and // therefore not reporting its length accurately.. export function getDependsOnOwnProps(mapToProps) { - return (mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined) + return mapToProps.dependsOnOwnProps !== null && + mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1 } // Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction, // this function wraps mapToProps in a proxy function which does several things: -// +// // * Detects whether the mapToProps function being called depends on props, which // is used by selectorFactory to decide if it should reinvoke on props changes. -// +// // * On first call, handles mapToProps if returns another function, and treats that // new function as the true mapToProps for subsequent calls. -// +// // * On first call, verifies the first result is a plain object, in order to warn // the developer that their mapToProps function is not returning a valid result. -// +// export function wrapMapToPropsFunc(mapToProps, methodName) { return function initProxySelector(dispatch, { displayName }) { const proxy = function mapToPropsProxy(stateOrDispatch, ownProps) { @@ -46,7 +49,10 @@ export function wrapMapToPropsFunc(mapToProps, methodName) { // allow detectFactoryAndVerify to get ownProps proxy.dependsOnOwnProps = true - proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) { + proxy.mapToProps = function detectFactoryAndVerify( + stateOrDispatch, + ownProps + ) { proxy.mapToProps = mapToProps proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps) let props = proxy(stateOrDispatch, ownProps) @@ -57,7 +63,7 @@ export function wrapMapToPropsFunc(mapToProps, methodName) { props = proxy(stateOrDispatch, ownProps) } - if (process.env.NODE_ENV !== 'production') + if (process.env.NODE_ENV !== 'production') verifyPlainObject(props, displayName, methodName) return props diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js index a6638f06b..e6fe8cae8 100644 --- a/src/utils/shallowEqual.js +++ b/src/utils/shallowEqual.js @@ -11,8 +11,12 @@ function is(x, y) { export default function shallowEqual(objA, objB) { if (is(objA, objB)) return true - if (typeof objA !== 'object' || objA === null || - typeof objB !== 'object' || objB === null) { + if ( + typeof objA !== 'object' || + objA === null || + typeof objB !== 'object' || + objB === null + ) { return false } @@ -22,8 +26,7 @@ export default function shallowEqual(objA, objB) { if (keysA.length !== keysB.length) return false for (let i = 0; i < keysA.length; i++) { - if (!hasOwn.call(objB, keysA[i]) || - !is(objA[keysA[i]], objB[keysA[i]])) { + if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { return false } } diff --git a/test/babel-transformer.jest.js b/test/babel-transformer.jest.js index b698b4f24..5e9b0631f 100644 --- a/test/babel-transformer.jest.js +++ b/test/babel-transformer.jest.js @@ -2,5 +2,5 @@ const path = require('path') const { createTransformer } = require('babel-jest') module.exports = createTransformer({ - configFile: path.resolve(__dirname, '../.babelrc.js'), + configFile: path.resolve(__dirname, '../.babelrc.js') }) diff --git a/test/install-test-deps.js b/test/install-test-deps.js index b6bfed38c..da74c899b 100644 --- a/test/install-test-deps.js +++ b/test/install-test-deps.js @@ -1,10 +1,10 @@ /* eslint no-console: 0 */ -'use strict'; +'use strict' -const { readdirSync, existsSync, copyFile, mkdirSync } = require('fs'); -const rimraf = require('rimraf'); -const { join } = require('path'); -const spawn = require("cross-spawn"); +const { readdirSync, existsSync, copyFile, mkdirSync } = require('fs') +const rimraf = require('rimraf') +const { join } = require('path') +const spawn = require('cross-spawn') const reactVersion = process.env.REACT || '16.6' readdirSync(join(__dirname, 'react')).forEach(version => { @@ -16,16 +16,16 @@ readdirSync(join(__dirname, 'react')).forEach(version => { const srcs = [ join(__dirname, '..', 'src', 'components'), join(__dirname, '..', 'src', 'connect'), - join(__dirname, '..', 'src', 'utils'), + join(__dirname, '..', 'src', 'utils') ] const dest = [ join(__dirname, 'react', version, 'test', 'components'), - join(__dirname, 'react', version, 'test', 'utils'), + join(__dirname, 'react', version, 'test', 'utils') ] const srcDest = [ join(__dirname, 'react', version, 'src', 'components'), join(__dirname, 'react', version, 'src', 'connect'), - join(__dirname, 'react', version, 'src', 'utils'), + join(__dirname, 'react', version, 'src', 'utils') ] if (!existsSync(join(__dirname, 'react', version, 'test'))) { @@ -66,24 +66,32 @@ readdirSync(join(__dirname, 'react')).forEach(version => { if (e) console.log(e) }) }) - copyFile(join(__dirname, '..', 'src', 'index.js'), join(__dirname, 'react', version, 'src', 'index.js'), e => { - if (e) console.log(e) - }) + copyFile( + join(__dirname, '..', 'src', 'index.js'), + join(__dirname, 'react', version, 'src', 'index.js'), + e => { + if (e) console.log(e) + } + ) }) - const cwd = join(__dirname, 'react', version); - if (existsSync(join(__dirname, 'react', version, 'node_modules', 'react', 'package.json'))) { - console.log(`Skipping React version ${version} ... (already installed)`); + const cwd = join(__dirname, 'react', version) + if ( + existsSync( + join(__dirname, 'react', version, 'node_modules', 'react', 'package.json') + ) + ) { + console.log(`Skipping React version ${version} ... (already installed)`) return } - console.log(`Installing React version ${version}...`); + console.log(`Installing React version ${version}...`) const installTask = spawn.sync('npm', ['install'], { cwd, - stdio: 'inherit', - }); + stdio: 'inherit' + }) if (installTask.status > 0) { - process.exit(installTask.status); + process.exit(installTask.status) } -}); +}) diff --git a/test/run-tests.js b/test/run-tests.js index dea48d663..d4057a474 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -7,8 +7,8 @@ let jestConfig = { collectCoverage: true, coverageDirectory: `${__dirname}/coverage`, transform: { - '.js$': `${__dirname}/babel-transformer.jest.js`, - }, + '.js$': `${__dirname}/babel-transformer.jest.js` + } } require('./install-test-deps.js') @@ -23,7 +23,7 @@ if (version.toLowerCase() === 'all') { } else { jestConfig = { ...jestConfig, - rootDir: `${__dirname}/react/${version}`, + rootDir: `${__dirname}/react/${version}` } } diff --git a/test/utils/shallowEqual.spec.js b/test/utils/shallowEqual.spec.js index 37bf9e9d5..6a63d9f6f 100644 --- a/test/utils/shallowEqual.spec.js +++ b/test/utils/shallowEqual.spec.js @@ -4,61 +4,53 @@ describe('Utils', () => { describe('shallowEqual', () => { it('should return true if arguments fields are equal', () => { expect( - shallowEqual( - { a: 1, b: 2, c: undefined }, - { a: 1, b: 2, c: undefined } - ) + shallowEqual({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined }) ).toBe(true) - expect( - shallowEqual( - { a: 1, b: 2, c: 3 }, - { a: 1, b: 2, c: 3 } - ) - ).toBe(true) + expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe( + true + ) const o = {} - expect( - shallowEqual( - { a: 1, b: 2, c: o }, - { a: 1, b: 2, c: o } - ) - ).toBe(true) + expect(shallowEqual({ a: 1, b: 2, c: o }, { a: 1, b: 2, c: o })).toBe( + true + ) - const d = function () {return 1} + const d = function() { + return 1 + } expect( - shallowEqual( - { a: 1, b: 2, c: o, d }, - { a: 1, b: 2, c: o, d } - ) + shallowEqual({ a: 1, b: 2, c: o, d }, { a: 1, b: 2, c: o, d }) ).toBe(true) }) it('should return false if arguments fields are different function identities', () => { expect( shallowEqual( - { a: 1, b: 2, d: function () {return 1} }, - { a: 1, b: 2, d: function () {return 1} } + { + a: 1, + b: 2, + d: function() { + return 1 + } + }, + { + a: 1, + b: 2, + d: function() { + return 1 + } + } ) ).toBe(false) }) it('should return false if first argument has too many keys', () => { - expect( - shallowEqual( - { a: 1, b: 2, c: 3 }, - { a: 1, b: 2 } - ) - ).toBe(false) + expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false) }) it('should return false if second argument has too many keys', () => { - expect( - shallowEqual( - { a: 1, b: 2 }, - { a: 1, b: 2, c: 3 } - ) - ).toBe(false) + expect(shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false) }) it('should return false if arguments have different keys', () => { @@ -70,50 +62,19 @@ describe('Utils', () => { ).toBe(false) }) - it('should compare two NaN values', () => { - expect( - shallowEqual( - NaN, - NaN - ) - ).toBe(true) + expect(shallowEqual(NaN, NaN)).toBe(true) }) it('should compare empty objects, with false', () => { - expect( - shallowEqual( - {}, - false - ) - ).toBe(false) - expect( - shallowEqual( - false, - {} - ) - ).toBe(false) - expect( - shallowEqual( - [], - false - ) - ).toBe(false) - expect( - shallowEqual( - false, - [] - ) - ).toBe(false) + expect(shallowEqual({}, false)).toBe(false) + expect(shallowEqual(false, {})).toBe(false) + expect(shallowEqual([], false)).toBe(false) + expect(shallowEqual(false, [])).toBe(false) }) it('should compare two zero values', () => { - expect( - shallowEqual( - 0, - 0 - ) - ).toBe(true) + expect(shallowEqual(0, 0)).toBe(true) }) }) }) diff --git a/test/utils/wrapActionCreators.spec.js b/test/utils/wrapActionCreators.spec.js index 728ae77b7..95f68d7b6 100644 --- a/test/utils/wrapActionCreators.spec.js +++ b/test/utils/wrapActionCreators.spec.js @@ -3,7 +3,6 @@ import wrapActionCreators from '../../src/utils/wrapActionCreators' describe('Utils', () => { describe('wrapActionCreators', () => { it('should return a function that wraps argument in a call to bindActionCreators', () => { - function dispatch(action) { return { dispatched: action @@ -24,7 +23,6 @@ describe('Utils', () => { const bound = wrapped(dispatch) expect(bound.action).not.toThrow() expect(bound.action().dispatched).toBe(actionResult) - }) }) })