Introducing mocha.throwError for better async error handling #985

Merged
merged 1 commit into from Dec 7, 2013

Conversation

Projects
None yet
5 participants
Contributor

jpbochi commented Sep 27, 2013

This mocha.throwError is supposed to be called by assertion libraries.

It will allows awesome diffs (like this) to be shown even when running async tests is a browser like phantomjs.

It's an alternative to visionmedia#278 and visionmedia#942

I plan to send a PR to chai, with a mirroring change.

Contributor

refack commented Oct 14, 2013

👍

Contributor

jpbochi commented Oct 15, 2013

@refack thanks for reviewing this.

@travisjeffery travisjeffery added a commit that referenced this pull request Dec 7, 2013

@travisjeffery travisjeffery Merge pull request #985 from jpbochi/async-error-handling
Introducing mocha.throwError for better async error handling

* jpbochi/async-error-handling:
  introduced mocha.throwError for better async error handling
e7364f3

@travisjeffery travisjeffery merged commit 9e652eb into mochajs:master Dec 7, 2013

1 check passed

default The Travis CI build passed
Details
Contributor

jpbochi commented Dec 7, 2013

@travisjeffery Nice! I'll start working on an PR for chai right away.

@tj tj commented on the diff Dec 8, 2013

if ('uncaughtException' == e) {
global.onerror = function() {};
+
+ var indexOfFn = uncaughtExceptionHandlers.indexOf(fn);
@tj

tj Dec 8, 2013

Contributor

way too verbose haha var i = would do :p

@travisjeffery travisjeffery added a commit that referenced this pull request Dec 8, 2013

@travisjeffery travisjeffery Fix var name (#985) 5cd2add

@jpbochi jpbochi commented on the diff Dec 8, 2013

support/tail.js
if ('uncaughtException' == e) {
global.onerror = function() {};
+
+ var indexOfFn = uncaughtExceptionHandlers.indexOf(fn);
+ if (indexOfFn != -1) { uncaughtExceptionHandlers.splice(indexOfFn, 1); }
@jpbochi

jpbochi Dec 8, 2013

Contributor

rename indexOfFn here, too? (I know this file is actually generated from the other)

@travisjeffery

travisjeffery Dec 8, 2013

Contributor

nah, this is the one i fixed. the other one in mocha.js is the generated one. don't bother with that one.

Contributor

jpbochi commented Dec 8, 2013

@travisjeffery @visionmedia I just create this PR (chaijs/chai#222) for chai to use mocha.throwError whenever available. Please review. :neckbeard:

Has this made it into should.js yet?

Contributor

jpbochi commented Jan 18, 2014

@christophercliff nope. I made a PR to chai. I should probably have created one for should.js first, sinc it's maintained by the same folks.

I'll see if I create one this weekend.

Contributor

tj commented Jan 18, 2014

actually now that im reading this again it doesn't quite make sense, it's only supported in the browser, and they're not uncaught, they're just assertion errors so those var names are a little wonky

Contributor

jpbochi commented Jan 20, 2014

@christophercliff There's one complication to implement that on should.js. Currently, there's no easy way to run its tests on a browser.

@visionmedia I'm figuring out a way to run all (or at least some) should.js's tests on a browser. Is it ok if I introduce karma there?

Contributor

jpbochi commented Jan 20, 2014

should.js relies on try+catch of AssertionError's for negative assertions. Unfortunately, this doesn't play out nice with mocha.throwError because the error will be reported to mocha even if you catch it later.

nchapman referenced this pull request in mozilla/fxa-content-server Mar 19, 2014

Merged

test(frontend): upgrade mocha for promise support and fix async tests #766

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