You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use rewire() in my Jest test files, JEST CLI starts reporting wrong lines when highlighting errors and failed test. I don't know if it's a Rewire or Jest issue, however everything works correctly when not calling rewire() and using normal require() instead.
Here's all you need to reproduce:
npm install jest rewire # Jest 24.8.0, Rewire 4.0.1
node --version # v10.15.3
npm init # Set "jest" as test command
// main.jsconstsum=(a,b)=>a+b;module.exports={ sum };
Now, if you run npm test, the test correctly runs and fails on the first expect(), but the third one is highlighted. Here's the output of Jest, note how expected and received values are correct, but highlighted is wrong:
Funnilly enough, if you don't use Rewire's __get__ to get the test function, but simply use main.sum instead, Jest highlights a different wrong line, the second expect():
Lastly, if you don't use Rewire altogether, including the main module with require('./main.js')and commenting out require('rewire'), everything is correct:
When I use
rewire()
in my Jest test files, JEST CLI starts reporting wrong lines when highlighting errors and failed test. I don't know if it's a Rewire or Jest issue, however everything works correctly when not callingrewire()
and using normalrequire()
instead.Here's all you need to reproduce:
Now, if you run
npm test
, the test correctly runs and fails on the firstexpect()
, but the third one is highlighted. Here's the output of Jest, note how expected and received values are correct, but highlighted is wrong:Funnilly enough, if you don't use Rewire's
__get__
to get the test function, but simply usemain.sum
instead, Jest highlights a different wrong line, the secondexpect()
:Lastly, if you don't use Rewire altogether, including the main module with
require('./main.js')
and commenting outrequire('rewire')
, everything is correct:Thanks.
The text was updated successfully, but these errors were encountered: