jest: unhelpful error stack from expectationResultFactory stackFormatter
I have got an error from jest which leaves me blind to the actual problem that caused it:
● api functional tests › Can do password reset
Failed: SyntaxError
at stackFormatter (node_modules/jest-jasmine2/build/expectationResultFactory.js:30:20)
at <anonymous>
Is it really necessary to create a new error there? Syntax error should always contain a line and collumn so couldn’t jest just pass that? https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/expectationResultFactory.js#L30
My node: 8.1.0 My jest: 20.0.4
EDIT:I’ve since took all of the code out of a test and run it inside babel-node. This error is the one that was swallowed:
Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:1014:11)
at exports._exceptionWithHostPort (util.js:1037:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)
From previous event:
at httpAdapter (/home/capaj/git_projects/looop/project-alpha/front-end/node_modules/axios/lib/adapters/http.js:18:10)
at dispatchRequest (/home/capaj/git_projects/looop/project-alpha/front-end/node_modules/axios/lib/core/dispatchRequest.js:52:10)
at __NR_wrappedThenHandler (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/newrelic/lib/instrumentation/promise.js:466:25)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
From previous event:
at Promise.__NR_wrappedThen (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/newrelic/lib/instrumentation/promise.js:424:23)
at Promise.<anonymous> (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/sequelize/lib/promise.js:21:17)
at Promise.__NR_wrappedThen [as then] (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/newrelic/lib/instrumentation/promise.js:424:23)
at Axios.request (/home/capaj/git_projects/looop/project-alpha/front-end/node_modules/axios/lib/core/Axios.js:58:23)
at Axios.(anonymous function) [as post] (/home/capaj/git_projects/looop/project-alpha/front-end/node_modules/axios/lib/core/Axios.js:78:17)
at Function.wrap (/home/capaj/git_projects/looop/project-alpha/front-end/node_modules/axios/lib/helpers/bind.js:9:15)
at Object.resetPassword (/home/capaj/git_projects/looop/project-alpha/front-end/src/api/user-api.js:15:20)
at test (/home/capaj/git_projects/looop/project-alpha/back-end/test/password-reset.js:38:40)
at <anonymous>
It’s really a shame when the only way to debug a failing jest test is to rewrite the test in raw node.js
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 19
- Comments: 31 (14 by maintainers)
Yes its pretty annoying…
Getting a variant of this -
In otherwise passing tests… works fine with 20, upgrading to 21 and these have started dropping all over.
These are tests using supertest on top of express, they are all responses with errors (which are what is being tested), with the call provoking the error occurring in the beforeAll() function.
What fixed this for me :
Changing from the callback style
To the promise style
I’m having the same issue, using
ts-jest
. My TS compiles just fine though.EDIT: Turns out it was due to using Axios, and the default Jest environment is not
node
, so it attempted to useXMLHTTPRequest
or something.oh yeah. I’ve seen this happen before, i’m still not sure when exactly this happens and what’s causing it, since most of the time we still have stack traces. But all of this logic will be replaced soon anyway
Upgrading to
jest@23.0.0-alpha.7
fixed it for us@thymikee @aaronabramov The problem seems to be using
await
on a rejectedPromise
directly in theit
function:give the error:
but if
it
is embedded in a function:it give the same warnings as when using
node
directly:edit: fix copy-paste of error message
It can be ported ish.
instanceof
doesn’t work properly (#2549), so we’ll probably have to duck type when checking if it’s an error or not. Other than that, should be straight forward.Reason of forking is discussed here: https://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html#breaking-changes and here: #3147
Getting the same behaviour as @awilkins and @dfroger - except I can’t use the workaround, because the library I’m testing uses just callbacks. Started occurring upon upgrading jest:
Thus is seems like a bug has been introduced, so I think the Enhancement label really should be changed to the Bug label @thymikee .