From 5a6c5db35bf33079852a9a5bebb5df59f7d4293f Mon Sep 17 00:00:00 2001 From: Michael Peyper Date: Fri, 26 Apr 2019 01:38:59 +1000 Subject: [PATCH] Use react-hooks-testing-library to test hooks (#1259) * Use react-hooks-testing-library to test hooks * Disable react/display-name rule with nested .eslintrc file --- package-lock.json | 21 +++++ package.json | 2 + test/hooks/.eslintrc | 5 ++ test/hooks/useActions.spec.js | 131 ++++++++--------------------- test/hooks/useDispatch.spec.js | 21 ++--- test/hooks/useRedux.spec.js | 39 +++------ test/hooks/useReduxContext.spec.js | 12 +-- test/hooks/useSelector.spec.js | 37 +++----- 8 files changed, 99 insertions(+), 169 deletions(-) create mode 100644 test/hooks/.eslintrc diff --git a/package-lock.json b/package-lock.json index d72df7a8f..806c6b00e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7178,11 +7178,32 @@ "scheduler": "^0.13.6" } }, + "react-hooks-testing-library": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/react-hooks-testing-library/-/react-hooks-testing-library-0.5.0.tgz", + "integrity": "sha512-qX4SA28pcCCf1Q23Gtl1VKqQk26pSPTEsdLtfJanDqm4oacT5wadL+e2Xypk/H+AOXN5kdZrWmXkt+hAaiNHgg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.4.2" + } + }, "react-is": { "version": "16.8.6", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz", "integrity": "sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==" }, + "react-test-renderer": { + "version": "16.8.6", + "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.8.6.tgz", + "integrity": "sha512-H2srzU5IWYT6cZXof6AhUcx/wEyJddQ8l7cLM/F7gDXYyPr4oq+vCIxJYXVGhId1J706sqziAjuOEjyNkfgoEw==", + "dev": true, + "requires": { + "object-assign": "^4.1.1", + "prop-types": "^15.6.2", + "react-is": "^16.8.6", + "scheduler": "^0.13.6" + } + }, "react-testing-library": { "version": "5.9.0", "resolved": "https://registry.npmjs.org/react-testing-library/-/react-testing-library-5.9.0.tgz", diff --git a/package.json b/package.json index cde6a6d1c..befbc307a 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,8 @@ "prettier": "^1.16.4", "react": "^16.8.6", "react-dom": "^16.8.6", + "react-hooks-testing-library": "^0.5.0", + "react-test-renderer": "^16.8.6", "react-testing-library": "^5.9.0", "redux": "^4.0.1", "rimraf": "^2.6.3", diff --git a/test/hooks/.eslintrc b/test/hooks/.eslintrc new file mode 100644 index 000000000..1de5b1a79 --- /dev/null +++ b/test/hooks/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "react/display-name": 0 + } +} diff --git a/test/hooks/useActions.spec.js b/test/hooks/useActions.spec.js index e87b80931..d0807ed44 100644 --- a/test/hooks/useActions.spec.js +++ b/test/hooks/useActions.spec.js @@ -1,6 +1,6 @@ import React from 'react' import { createStore } from 'redux' -import * as rtl from 'react-testing-library' +import { renderHook } from 'react-hooks-testing-library' import { Provider as ProviderMock, useActions } from '../../src/index.js' describe('React', () => { @@ -28,58 +28,29 @@ describe('React', () => { dispatchedActions = [] }) - afterEach(() => rtl.cleanup()) - it('supports a single action creator', () => { - const Comp = () => { - const inc1 = useActions(() => ({ type: 'inc1' })) - - return ( - <> -