我想用jest-dom做单元测试。我有一个包含属性和方法的组件。单元测试是这样的
import React from "react";
import {render} from '@testing-library/react'
import MultiCheck,{Option} from "./MultiCheck";
describe('MultiCheck', () => {
describe('initialize', () => {
it('renders the label if label provided', () => {
// TODO
//TS2739: Type '{ handleItemClick: any; options: any; }'
// is missing the following properties from type 'Props': columns, values, selectedAll
const wrapper = render(<MultiCheck handleItemClick={} options={}/>)
});
});
});我不知道怎么做笑话测试?有人能帮我吗?
发布于 2020-08-14 19:10:54
您必须将组件使用的所有属性传递给。简单的解决方法可以是:拥有下面这样的东西:
const defaultProps = {
handleItemClick: // initial mock value,
options: // initial mock value,
......... all props here
}然后将其传递给您的组件,如下所示:
const wrapper = render(<MultiCheck {...defaultProps}/>)https://stackoverflow.com/questions/63409132
复制相似问题