-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled promise rejection ... Error: Network Error #122
Comments
@smallstepstoday Hi, I believe that I have the same issue here. const axiosMockAdapter = require('axios-mock-adapter')
const axios = require('axios')
const axiosMock = new axiosMockAdapter(axios, {delayResponse: 200})
axiosMock.onGet('/aaa').networkError()
axiosMock.onGet('/bbb').timeout()
axiosMock.onGet('/ccc').reply(500)
test('aaa', done => {
axios.get('/aaa')
.then(() => done())
.catch(e => done())
})
test('bbb', done => {
axios.get('/bbb')
.then(() => done())
.catch(e => done())
})
test('ccc', done => {
axios.get('/ccc')
.then(() => done())
.catch(e => done())
}) test case environment:
error log of
If I delete
|
这有可能是 axios-mock-adapter 的一个错误,导致 https://github.com/Liu233w/acm-statistics/blob/e12537f643ee2fdcc80cdb70733e43f5602dae24/crawler/__test__/functionGenerator.test.js#L169 测试失败。 refer to: ctimmerm/axios-mock-adapter#122
Well, I just tested it on mocha, and all the test passed. While jest fails only when the According to jest's document, the default environment in Jest is a browser-like environment through jsdom. It seems like axios-mock-adapter behaves differently from node environment and 'browser-like' environment. I don't know if it's a bug or feature. I created a repo to reproduce it. |
如果不这么做, axios 的 networkError 测试会失败。 目前还不知道失败的原因,参考 ctimmerm/axios-mock-adapter#122 (comment) 获取更详细的信息
如果不这么做, axios 的 networkError 测试会失败。 目前还不知道失败的原因,参考 ctimmerm/axios-mock-adapter#122 (comment) 获取更详细的信息
This is running under |
I have spent the weekend attempting to resolve this issue, and I believe this to be a bug in
axios-mock-adapter
. Having said that, if that is not the case, I hope that someone could point out the flaw in the code below. The documentation on the networkError() function is sparse to say the least, and no amount of stackoverflow.com goodness seems to shed any additional light on this one.My project uses
axios-mock-adapter
at 1.14.1, and I am attempting to simulate a network error (also a timeout, but one thing at a time). I have attempted to cover all the bases in an attempt to trap the Unhandled Promise Rejection that is reported by Node, so the code below is perhaps a bit more verbose than it needs to be. (Happy to receive any pointers...)The code to test is a follows:
The output received when the test runs is:
Thanks for looking into this issue. Has me stumped!
The text was updated successfully, but these errors were encountered: