【发布时间】:2020-10-31 01:05:33
【问题描述】:
let wrapper;
const setState = jest.fn();
const useStateSpy = jest.spyOn(React, "useState")
useStateSpy.mockImplementation((init) => [init, setState]);
beforeEach(() => {
wrapper = Enzyme.mount(Enzyme.shallow(<AddOption/>).get(0))
});
afterEach(() => {
jest.clearAllMocks();
});
我正在尝试模拟这一行的状态 -
useStateSpy.mockImplementation((init) => [init, setState]);
我收到错误:
Type 'any[]' is missing the following properties from type '[unknown, Dispatch<unknown>]': 0, 1ts(2739)
我不确定如何修复此错误,也无法在网上找到很多关于针对此特定用例修复此类错误的信息。
【问题讨论】:
-
为什么要同时使用mount和shallow来渲染AddOption?
-
@Rostyslav 我正在按照在线指南为表单组件编写测试,所以老实说我不太确定......我是反应测试的新手,但网上的很多示例都没有使用打字稿另外,就像我一样 - dev.to/austinbh/…
标签: reactjs typescript jestjs enzyme