我最近在开玩笑地写测试用例。我有一个要求,如应该检查内部函数是否被调用。有人可以帮我吗?
这是index.js的代码
componentDidMount() {
this.onSetActionableStateListener = (param) => this.onSetActionableState(param[0]);
client.on('setActionableState', this.onSetActionableStateListener);
}
我正在这样编写index.test.js中的代码
it('should call onSetActionableState in componentDidMount', () => {
wrapper.instance().componentDidMount();
// const onSetActionableState = jest.fn();
expect(wrapper.instance().onSetActionableState).toBeCalled();
});
我想测试是否调用了onSetActionableState吗?