我要测试这两个功能是否在玩笑/酶中调用。这是我要测试的代码:
Promise.resolve(this.props.removeFromShortlist({
mppId: mppProduct.id,
})).then(() => {
this.props.shortlistEvent({
event: 'shortlist-remove',
value: _.map(this.props.shortlist, mpp => mpp.product.id).join(','),
})
})
这是我的测试:
it('calls the removeFromShortlist function if the product is in the shortlist', () => {
const removeFromShortlistSpy = jest.fn()
const overriddenProps = {
...props,
removeFromShortlist: removeFromShortlistSpy,
}
const component = shallow(<MppProduct {...overriddenProps} />)
component.children().find('mppLogo').dive().find('shortlistButton').dive().simulate('click')
expect(removeFromShortlistSpy).toBeCalled()
})
第一个测试通过了,但是第二个没有通过。如何解析removeFromShortlist
函数,然后检查是否调用了shortlistEvent
函数?