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 (
- <>
-
- >
- )
- }
-
- const { container } = rtl.render(
-
-
-
+ const { result } = renderHook(
+ () => useActions(() => ({ type: 'inc1' })),
+ { wrapper: props => }
)
- const bInc1 = container.querySelector('#bInc1')
-
- rtl.fireEvent.click(bInc1)
+ result.current()
expect(dispatchedActions).toEqual([{ type: 'inc1' }])
})
it('supports an object of action creators', () => {
- const Comp = () => {
- const { inc1, inc2 } = useActions({
- inc1: () => ({ type: 'inc1' }),
- inc2: () => ({ type: 'inc', amount: 2 })
- })
-
- return (
- <>
-
-
- >
- )
- }
-
- const { container } = rtl.render(
-
-
-
+ const { result } = renderHook(
+ () =>
+ useActions({
+ inc1: () => ({ type: 'inc1' }),
+ inc2: () => ({ type: 'inc', amount: 2 })
+ }),
+ { wrapper: props => }
)
- const bInc1 = container.querySelector('#bInc1')
- const bInc2 = container.querySelector('#bInc2')
-
- rtl.fireEvent.click(bInc1)
- rtl.fireEvent.click(bInc2)
+ result.current.inc1()
+ result.current.inc2()
expect(dispatchedActions).toEqual([
{ type: 'inc1' },
@@ -88,31 +59,17 @@ describe('React', () => {
})
it('supports an array of action creators', () => {
- const Comp = () => {
- const [inc1, inc2] = useActions([
- () => ({ type: 'inc1' }),
- () => ({ type: 'inc', amount: 2 })
- ])
-
- return (
- <>
-
-
- >
- )
- }
-
- const { container } = rtl.render(
-
-
-
+ const { result } = renderHook(
+ () =>
+ useActions([
+ () => ({ type: 'inc1' }),
+ () => ({ type: 'inc', amount: 2 })
+ ]),
+ { wrapper: props => }
)
- const bInc1 = container.querySelector('#bInc1')
- const bInc2 = container.querySelector('#bInc2')
-
- rtl.fireEvent.click(bInc1)
- rtl.fireEvent.click(bInc2)
+ result.current[0]()
+ result.current[1]()
expect(dispatchedActions).toEqual([
{ type: 'inc1' },
@@ -133,37 +90,21 @@ describe('React', () => {
const store = createStore(reducer)
dispatchedActions = []
- const Comp = () => {
- const { adjust } = useActions({
- adjust: (amount, isAdd = true) => ({
- type: 'adjust',
- amount,
- isAdd
- })
- })
-
- return (
- <>
-