说我有这个:
componentDidMount() {
window.Something.windowFunction(EVENT_HANDLER, this.myFunc)
}
myFunc() {
// test that this was called
}
如何模拟窗口对象以确保进入myFunc
我已经做到了
const mockFn = jest.fn().mockImplementation((eventHandler, eventCallback) => {
return eventCallback()
})
global.Something = {
windowFunction: mockFn('event-handler', () => jest.fn()),
}
但它从未调用myFunc