upload测试无法通过
来源:10-13 异步怎样测试? - Upload 测试第一部分

AlmostSire
2020-08-19
老师我在跟着课程写测试case的时候报这样一个错误,红色字体错误信息如何解决
写回答
2回答
-
同学你好 请提供一下测试代码和组件代码欧。 同学可以将自己的代码上传 github 或者 gitee,这样方便我查看也方便你跟踪学习进度。
012020-08-20 -
张轩
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' })) })
00
相似问题