我正在为我的功能组件编写测试用例,在其中使用了useDispatch和
useState。如何为以下组件编写测试用例。
import componentLoaderAction from "../../../redux/actions/componentLoaderAction";
import { useSelector, useDispatch } from 'react-redux';
import ComponentLoader from '../../component-loader/component-loader';
const HelloType = ({ props, data }) => {
const dispatch = useDispatch();
dispatch(componentLoaderAction.loadStep(1));
const configurations = {
navigations: {
........
}
};
return (
<div className="main-container">
...
<ComponentLoader configurations={configurations} data={data}> </ComponentLoader>
</div>
);
};
我将测试用例编写如下: HelloType.test.js
jest.mock("react-redux", () => ({
useSelector: jest.fn(),
useDispatch: jest.fn()
}));
test('Component should render', () => {
const component = renderer.create(< HelloType />);
expect(component.toJSON()).toMatchSnapshot();
});
我不确定这是否正确。但是当运行它时,它给我错误,因为“调度不是 定义”,并指向我实际的js文件HelloType.js。请帮我提供快照的测试用例 和事件。怎么做?