Description
Sorry for removing issue template. Since the React 16.8 is out we can start to work on hooks support in enzyme now. Previously I tried to open PR in #2008 to help with this but found out that there are too many apis in React hooks. After some thinking I feel it's better to track all of the supports / PR in one issues, and create one PR for each hooks api (useState
, useEffect
, etc).
- useState (Testing Hooks with shallow: Invariant Violation #1938, Testing Hooks with mount: onChange not called #1996, Test case PR [Tests] add hooks tests #2008 hooks testcase written #2029 [Hooks Testing] Added Test cases for useState, useEffects & customHooks #2041)
- useEffect (Test case PR Wrap mount renderer render with reactTestUtils.act() #2034 [Hooks Testing] Added Test cases for useState, useEffects & customHooks #2041 ; Currently not work in shallow renderer, see Add option in shallow renderer to run effects/componentDidUpdate/componentDidMount facebook/react#15275)
- useContext (Test case PR [Hooks Testing] Added Test cases for useState, useEffects & customHooks #2041)
- useReducer (Test case PR [Hooks Testing] Added Test cases for useState, useEffects & customHooks #2041)
- useCallback (Test case PR React hooks test case part 3 -- useCallback #2148)
- useMemo (Test case PR React hooks test case part 2 -- useMemo #2144)
- useRef (Testing Hooks with shallow: Invariant Violation #1938, Test case PR Add useRef, useImperativeHandle, useDebugValue tests #2162)
- useImperativeHandle (useImperativeHandle callback never called (when rendering w/ enzyme) #2039, Test case PR Add useRef, useImperativeHandle, useDebugValue tests #2162)
- useLayoutEffect (Test case PR React hooks test cases part 1 -- useLayoutEffect #2121)
- useDebugValue(Test case PR Add useRef, useImperativeHandle, useDebugValue tests #2162)
- custom hooks (Testing Hooks with mount: onChange not called #1996)
known issues (some are resolved with newer version of react):
-
setState
returned fromuseState
not works withshallow
before react@16.8.5 . Fixed in [Shallow] Implement setState for Hooks and remount on type change facebook/react#15120 . -
useEffect
anduseLayoutEffect
not works withshallow
because react shallow renderer doesn't run it. (Add option in shallow renderer to run effects/componentDidUpdate/componentDidMount facebook/react#15275) -
useCallback
doesn't memoize callback in react shallow renderer (useCallback doesn't memoize callback in shallow renderer facebook/react#15774)
Currently I'm working in useState
(#2008) and I'm glad to see if anyone else would like to help to support other apis. For now we need to add many tests to make sure what is working in enzyme, and what is not, then add patch / feature into it. I can help to maintain the above checklist if there are any related issues / PR .
I'm simply volunteer to do this and not a main maintainer here though so @ljharb if you have had any plan / schedule on this feel free to tell me and I can change or close this :-)