当组件包装在forwardRef 中时,您打算如何处理测试文件中的模拟组件?mockImplementation 不在方法上,而是在属性渲染上。
import React from 'react';
import Component from './Component';
import mocked from 'ts-jest/utils'
jest.mock('./Component');
const mockComponent(Component);
mockComponent.mockImplementation(() => <></>) /* this returns type error that mockImplementation is not a function */
mockComponent.render.mockImplementation(() => <></>) /* this works but get a typescript error */
Run Code Online (Sandbox Code Playgroud)
我看到的打字稿错误是
TS2339: Property 'render' does not exist on type 'MockedFunction "li", {}>, "button" | "slot" | "style" | "title" | "className" | "classes" | "innerRef" | "selected" | "dense" | "key" | "value" | "defaultChecked" …Run Code Online (Sandbox Code Playgroud)