【发布时间】:2018-10-01 05:50:24
【问题描述】:
我有一个函数getBookingStateObject,它调用另一个函数getBookingStateButtons。依次getBookingStateButtons 调用另外两个函数linkButtons 和sendEventButtons。
我正在尝试为上述场景编写测试。我的测试文件中有以下内容。
import {
getBookingStateButtons,
getBookingStateObject,
linkButtons,
sendEventButtons,
} from './bookingStates'
jest.mock('getBookingStateButtons', () => jest.fn())
jest.mock('linkButtons', () => jest.fn())
jest.mock('sendEventButtons', () => jest.fn())
it('calls getBookingStateButtons, linkButtons, sendEventButtons', () => {
getBookingStateObject({ aasm_state: 'created' }, '123')
expect(getBookingStateButtons).toHaveBeenCalledWith({
bookingId: '123',
events: [{ event: 'mark_requested', type: 'secondary' }],
links: [{ to: 'edit' }],
})
expect(linkButtons).toHaveBeenCalledWith({
to: 'edit',
type: 'secondary',
})
expect(sendEventButtons).toHaveBeenCalledWith({
event: 'mark_requested',
type: 'secondary',
})
})
当我运行测试时,我收到以下错误:
Cannot find module 'getBookingStateButtons' from 'bookingStates.spec.tsx'
我是开玩笑的新手,我做错了什么?
【问题讨论】:
标签: javascript unit-testing jestjs