From 3cb9dc67166ea8366455c9dbc23ffd5a6e01c44c Mon Sep 17 00:00:00 2001 From: Michael Peyper Date: Wed, 24 Apr 2019 16:47:04 +1000 Subject: [PATCH 1/2] Use react-hooks-testing-library to test hooks --- package-lock.json | 21 +++++ package.json | 2 + test/hooks/useActions.spec.js | 133 +++++++++-------------------- test/hooks/useDispatch.spec.js | 23 ++--- test/hooks/useRedux.spec.js | 40 ++++----- test/hooks/useReduxContext.spec.js | 12 +-- test/hooks/useSelector.spec.js | 38 +++------ 7 files changed, 100 insertions(+), 169 deletions(-) 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/useActions.spec.js b/test/hooks/useActions.spec.js index e87b80931..1df295962 100644 --- a/test/hooks/useActions.spec.js +++ b/test/hooks/useActions.spec.js @@ -1,6 +1,8 @@ +/*eslint-disable react/display-name*/ + 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 +30,29 @@ describe('React', () => { dispatchedActions = [] }) - afterEach(() => rtl.cleanup()) - it('supports a single action creator', () => { - const Comp = () => { - const inc1 = useActions(() => ({ type: 'inc1' })) - - return ( - <> -