upload测试无法通过

来源:10-13 异步怎样测试? - Upload 测试第一部分

AlmostSire

2020-08-19

老师我在跟着课程写测试case的时候报这样一个错误,红色字体错误信息如何解决图片描述

写回答

2回答

张轩

2020-08-20

同学你好 请提供一下测试代码和组件代码欧。 同学可以将自己的代码上传 github 或者 gitee,这样方便我查看也方便你跟踪学习进度。

0
1
AlmostSire
https://github.com/AlmostSire/almostlover.git 老师这是我的代码地址,上面的问题我百度解决了,但是后续断言一样过不了,求老师帮帮我
2020-08-20
共1条回复

张轩

2020-08-21

同学你好 看了你的源代码 你的之前的错误 是因为后面没有添加await 造成的  没必要那么改,后面断言没过是因为 你的 onSuccess 和 onChange 的参数不是 File 对象,而是一个自定义的复杂数据结构。我给你改好了,你看看。

it('upload process should works fine', async () => {
    const { queryByText, getByText } = wrapper
    mockedAxios.post.mockImplementation(() => {
        return Promise.resolve({ 'data': 'cool' })
    })
   expect(uploadArea).toBeInTheDocument()
   expect(fileInput).not.toBeVisible()
   fireEvent.change(fileInput, { target: { files: [testFile] }})
   expect(queryByText('spinner')).toBeInTheDocument()
   await wait(() => {
       expect(queryByText('check-circle')).toBeInTheDocument()
   })
   expect(testProps.onSuccess).toHaveBeenCalledWith('cool', expect.objectContaining({
       raw: testFile,
       status: 'success',
       name: 'test.png'
   }))
    expect(testProps.onChange).toHaveBeenCalledWith(expect.objectContaining({
        raw: testFile,
        status: 'success',
        name: 'test.png'
    }))
})


0
0

React18+TS高仿AntD从零到一打造组件库

设计,开发,测试,发布再到 CI/CD,从0到1造轮子

2122 学习 · 959 问题

查看课程