【发布时间】:2020-09-21 00:27:18
【问题描述】:
我在 React 中使用功能组件,我需要为功能组件中的方法编写单元测试用例。
import React from 'react';
function print(){
console.log('hello');
}
function Welcome(props){
return <h1>{props.name}</h1>;
}
export default Welcome;
开玩笑和酶:
test (method print , ()=> {
const container = shallow(<Welcome />).instance().print()
}
instance : TypeError Cannot read property of null
我读过功能组件在 React 16+ 中没有实例。有人可以帮助建议一种为功能组件中的方法编写单元测试用例的方法吗?
【问题讨论】:
标签: reactjs unit-testing jestjs enzyme react-functional-component