jest-react-hooks-shallow
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -6,5 +6,5 @@ "use strict"; | ||
const react = jestInstance.requireActual('react'); | ||
jestInstance.mock('react', () => (Object.assign(Object.assign({}, react), { useEffect: mock_use_effect_1.default() }))); | ||
jestInstance.mock('react', () => (Object.assign(Object.assign({}, react), { useEffect: mock_use_effect_1.default(), useLayoutEffect: mock_use_effect_1.default() }))); | ||
}; | ||
exports.default = enableHooks; | ||
//# sourceMappingURL=enable-hooks.js.map |
{ | ||
"name": "jest-react-hooks-shallow", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "React Hooks for shallow rendering", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/mikeborozdin/jest-react-hooks-shallow", |
@@ -7,3 +7,3 @@ jest-react-hooks-shallow | ||
This package makes React Hooks (namely, `useEffect()`) work with shallow rendering. In other words, you can use enzyme. Yay! | ||
This package makes React Hooks (namely, `useEffect()` and `useLayoutEffect()`) work with shallow rendering. In other words, you can use enzyme. Yay! | ||
@@ -13,4 +13,12 @@ Installation | ||
Just install this package and add these lines to your Jest setup file (specified by `setupFilesAfterEnv`): | ||
Just install this package with | ||
``` | ||
npm install --save-dev jest-react-hooks-shallow | ||
# or | ||
yarn add --dev jest-react-hooks-shallow | ||
``` | ||
and add these lines to your Jest setup file (specified by `setupFilesAfterEnv`): | ||
``` | ||
@@ -23,3 +31,3 @@ import enableHooks from 'jest-react-hooks-shallow; | ||
And voilà - `useEffect()` will work with shallow rendering. From this moment on your test don't need to know anything about `useEffect()`. After all, it's a mere implementation detail. | ||
And voilà - `useEffect()` and `useLayoutEffect()` will work with shallow rendering. From this moment on your test don't need to know anything about `useEffect()`. After all, it's a mere implementation detail. | ||
@@ -111,6 +119,6 @@ Testing | ||
|-----|------| | ||
|`useEffect`|Supported| | ||
|`useLayoutEffect`|Coming soon| | ||
|`useEffect`|✅| | ||
|`useLayoutEffect`|✅| | ||
|`useImperativeHandle`|Coming soon| | ||
|`useDebugValue`|Coming soon| | ||
|`useDebugValue`|No support plans| | ||
@@ -128,3 +136,3 @@ All other hooks (e.g. `useState()`, `useReducer()`) already work with shallow rendering. | ||
Actually, it's not enzyme's fault that `useEffect()` doesn't work in shallow rendering. In fact, enzyme does **not** actually performs shallow rendering. Its `shallow()` function merely invokes shallow rendering of `react-test-renderer`. | ||
Actually, it's not enzyme's per se fault that `useEffect()` doesn't work in shallow rendering. It relies on `react-test-renderer` for some aspects of shallow rendering. And it is `react-test-renderer` that implements certain hooks, like `useState()` and does not implement the other ones (e.g. `useEffect()`). | ||
@@ -131,0 +139,0 @@ Now, `react-test-renderer` is part of the React library. And there is a [PR](https://github.com/facebook/react/pull/16168) that brings `useEffect()` to shallow rendering. However, that PR has been closed by Facebook. |
@@ -13,3 +13,4 @@ import mockUseEffect from "./mock-use-effect/mock-use-effect"; | ||
...react, | ||
useEffect: mockUseEffect() | ||
useEffect: mockUseEffect(), | ||
useLayoutEffect: mockUseEffect(), | ||
})); | ||
@@ -16,0 +17,0 @@ }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12882
150
148