开玩笑/酶中的Promise.resolve测试

时间:2018-11-10 20:23:36

标签: reactjs ecmascript-6 promise jestjs enzyme

我要测试这两个功能是否在玩笑/酶中调用。这是我要测试的代码:

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函数?

0 个答案:

没有答案