报错如图,代码我看了一下跟老师的代码几乎是一样的:
test('should reject on network errors', () => {
const resolveSpy = jest.fn((res: AxiosResponse) => {
return res
})
const rejectSpy = jest.fn((err: AxiosError) => {
return err
})
jasmine.Ajax.uninstall()
return axios('/foo')
.then(resolveSpy)
.catch(rejectSpy)
.then(next)
function next(reason: AxiosResponse | AxiosError) {
jasmine.Ajax.install()
expect(resolveSpy).not.toHaveBeenCalled()
expect(rejectSpy).toHaveBeenCalled()
expect(reason instanceof Error).toBeTruthy()
expect((reason as AxiosError).message).toBe('Network Error')
expect(reason.request).toEqual(expect.any(XMLHttpRequest))
}
})
jasmine.Ajax.uninstall()的调用似乎没有触发request.onerror事件,而是直接进入了response的validateStatus的校验。