【发布时间】:2019-11-28 18:19:36
【问题描述】:
我有这个代码:
const eventNames = ['ready', 'click']
const node = ReactDOM.findDOMNode(mapRef)
const mapConfig = { streetViewControl: false }
this.map = new maps.Map(node, mapConfig)
eventNames.forEach(e => {
this.listeners[e] = this.map.addListener(e, this.handleEvent(e))
})
我想对其进行测试,但收到此错误:this.map.addListener is not a function。我是这样嘲讽的:
window.addEventListener = jest.fn()
const google = {
maps: {
LatLng: jest.fn(),
Map: jest.fn(),
event: jest.fn()
}
}
const wrapper = shallow(
<Map google={google}>
<Component />
</Map>
)
谁能帮忙模拟一下这部分?
提前谢谢你
【问题讨论】:
标签: javascript reactjs jasmine jestjs