【发布时间】:2020-01-22 11:11:47
【问题描述】:
我正在使用 Jest 开发一个 React 应用程序。
我想测试一个导入的模块组件方法(closemodal):
<Modal
visible={this.state.showModal}
closemodal={() => this.setState({ showModal: false })} // <= this one
type="slideInDown"
>
我尝试在我的单元测试中窥探这样的 Modal closemodal 方法:
import Modal from "react-animated-modal";
let spyOnCloseModal;
beforeEach(() => {
spyOnCloseModal = jest.spyOn(Modal, "closemodal");
wrapper = shallow(<App />);
});
但是当 UT 运行时我得到这个错误:
Cannot spy the closemodal property because it is not a function; undefined given instead
【问题讨论】:
标签: reactjs unit-testing jestjs