我进行了以下测试,但得到以下错误:" api : unable to fetch api token。“我尝试使用shallow
而不是mount
,但它返回相同的错误。
describe('CreateTemplateModal', () => {
let props, el
const modal = function () {
if (!el) el = mount(<CreateTemplateModal {...props} />)
return el
}
beforeEach(() => {
props = {
onSubmit: jest.fn().mockReturnValue(Promise.resolve()),
}
el = undefined
})
it('calls onSubmit when create template button is clicked', () => {
const el = modal().setState({
title: 'new template',
jurisdiction: 'nsw',
description: 'random',
})
el.find('#create-template-btn').simulate('submit')
expect(props.onSubmit).toHaveBeenCalled()
})
})
发布于 2019-01-14 15:07:14
由于您正在模拟onSubmit函数,因此我认为在onSubmit函数中或在单击#create-template-btn
之后不会调用api。由于您还没有共享CreateTemplateModal
代码,我建议您检查CreateTemplateModal
组件中的构造函数或render()
函数。绝对存在调用token API的情况
https://stackoverflow.com/questions/54141690
复制相似问题