Jest: Throwing a non-Error object with a property called "stack" causes test to hang

Created on 22 Oct 2020  路  5Comments  路  Source: facebook/jest

馃悰 Bug Report

It seems that if you throw an object that is not an instance of Error, but includes a property named stack that is an object, the test will never complete.

No error is reported on my machine, but the repl.it environment prints the error TypeError: stack.replace is not a function, though the test still hangs regardless.

To Reproduce

add this to a test file:

test("throw object with stack prop", () => {
  throw { stack: [] };
});

Expected behavior

Test fails, but remainder of test suite continues

Link to repl or repo (highly encouraged)


https://repl.it/repls/GrossDarlingLocks

envinfo

 System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  Binaries:
    Node: 14.9.0 - ~/.nvm/versions/node/v14.9.0/bin/node
    npm: 6.14.8 - ~/.nvm/versions/node/v14.9.0/bin/npm
  npmPackages:
    jest: ^26.4.2 => 26.4.2 
Bug Help Wanted Needs Triage

All 5 comments

Seems likely, yeah. Anybody up for a PR fixing this? Anything thrown, ever, should be unknown and we then narrow down the type afterwards. Assuming stack is a string is unsafe as can be seen by this issue.

Hello @SimenB, I was trying to work on this issue.
Do I have to run yarn run build every time I make changes in jest/packages/jest-jasmine2/src/reporter.ts to test the changes?

You can run yarn watch to build once and then set up a watcher 馃檪

This seems to also fail with jest-circus in a different way BTW
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitalibozhko picture vitalibozhko  路  138Comments

simon360 picture simon360  路  78Comments

eldh picture eldh  路  84Comments

sterpe picture sterpe  路  70Comments

SimenB picture SimenB  路  69Comments