所以我终于找到了如何测试依赖于useContext和useReducer的钩子。由于在该主题上的备忘非常差,所以我无法找到如何从Profile组件进行存储和分发以及深入研究Profile组件?当我在test()或find(Profile)中console.log 包装器时,我从控制台获得 React Wrapper {}
import React, { useReducer } from 'react'
import { mount } from 'enzyme'
import Profile from './Profile'
import {Store} from '../../App'
import {initialState, reducer} from '../../reducer'
const TestingHook = ({children}) => {
const [store, dispatch] = useReducer(reducer, initialState);
return <Store.Provider value={{store: store, dispatch: dispatch}}>
{children}
</Store.Provider>
}
describe('Testing Profile page', () => {
test('', () => {
const wrapper = mount(<TestingHook><Profile /></TestingHook>)
})
})