可以通过以下方式模拟该方法:
it('handleNameInput', () => { let wrapper = shallow(<MyComponent/>); wrapper.instance().searchDish = jest.fn(); wrapper.update(); wrapper.instance().handleNameInput('BoB'); expect(wrapper.instance().searchDish).toBeCalledWith('BoB'); })您还需要在被测组件的包装器上调用.update,以便正确注册模拟功能。
语法错误来自错误的分配(您需要将方法分配给实例)。我的其他问题来自
.update()模拟方法后不调用。



