Assertion.includeStack = true doesn't work on Firefox #100

jfirebaugh opened this Issue Oct 2, 2012 · 6 comments


None yet

6 participants

Chai.js Assertion Library member

Stack trace collection requires Error.collectStackTrace, which is a V8 extension.

For other browsers, can we maybe throw an Error, immediately catch it, and copy over the stack property?

/cc @ragalie


The "Assertion.includeStack is true" test in the Online Test Suite is failing in Safari 6.0.2 on OS X 10.8.2 too. Safari does not use V8 either.


Bump this, it can be quite debugging friendly with stack trace instead of just the assertion error.

Chai.js Assertion Library member

Hey @jfirebaugh thanks for the issue, and thanks @ryandesign and @garryyao for commenting. If any of you want to make an attempt at a Pull Request for this, I'd certainly take a look at it. @jfirebaugh's solution sounds pretty reasonable.

Chai.js Assertion Library member

Thanks @keithamus for bringing this back into the fold. When this was first reported, libs like stacktrace.js did not yet exist or were highly unstable. Also, since then, we have extracted our error constructor out into its own module as assertion-error.

Just another possible route to explore.


does being fixed in Firefox help here?

@nevir nevir referenced this issue in Polymer/web-component-tester Nov 24, 2014

Better errors for Firefox #55

Chai.js Assertion Library member

Good find @julienw, but I'm not sure it helps as chai doesn't use window.onerror. It's mostly, as @jfirebaugh suggests, that we use Error.captureStackTrace which is non-standard. The simplest (and most compatible) way to get this for all browsers seems to be instead using (new Error()).stack. The downside of grabbing the stack from a new error (and likely the reason for using Error.captureStackTrace) is that you cannot reliably chop off the lines within Chai, and so users have to decipher which part of the stack starts being their code.

Should be a pretty easy one to tackle is someone wants to make a PR and nab the credit 😉. Simply add something like:

} else {
    this.stack = (new Error(this.message)).stack;

After line 40, in error.js

(And of course, add some nice tests to prove it works 😜)

@simonzack simonzack added a commit to simonzack/chai that referenced this issue Feb 19, 2015
@simonzack simonzack fix to #100 42107ff
@simonzack simonzack referenced this issue in chaijs/assertion-error Feb 20, 2015

fixes `.stack` on firefox #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment