mochajs / mocha

β˜•οΈ simple, flexible, fun javascript test framework for node.js & the browser

Home Page:https://mochajs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug: Browser doesn't include call stack for global uncaught errors

JoshuaKGoldberg opened this issue Β· comments

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

When an uncaught error occurs during a test in browsers, you'd expect to see the call stack. That's useful.

Error: Oh no!
    at inner (test.example.js:8:15)

Actual

Mocha's browser error handling code was written before browsers gave nice stacks (eb58761).

Error: Error: Oh no! (http://127.0.0.1:8081/test.example.js:8)

Minimal, Reproducible Example

Using a minimal browser setup such as in mochajs/mocha-examples#72:

it("example", (done) => {
    function inner() {
        throw new Error("Oh no!");
    }

    setTimeout(inner);
});

Versions

Mocha: 10.3.0

Additional Info

This was filed long ago in #2167, then a fix proposed in #3952. Since #2167 is quite old, re-filing to be more current.