Skip to content

Commit

Permalink
Add cross-frame compatible Error checking for fail
Browse files Browse the repository at this point in the history
  • Loading branch information
outdooricon committed Jun 19, 2015
1 parent 44b0045 commit 3fcca2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Runner.prototype.fail = function(test, err) {
++this.failures;
test.state = 'failed';

if (!(err instanceof Error)) {
if (!(err instanceof Error || err && typeof err.message == 'string')) {
err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');

This comment has been minimized.

Copy link
@sarkiroka

sarkiroka Jun 29, 2015

drop the original stacktrace? why? you should inform the developer about the original error, not just funny(?) message. for example:
err = new Error('the ' + type(err) + ' ' + stringify(err) + ' (' + err.stack.substring(0, err.stack.indexOf("\n", err.stack.indexOf("\n") + 1)) + ') ' + ' was thrown, throw an Error :)');
a little part of original stacktrace instead of "the error {} was thrown, throw an Error :)" meaningless funny message.
under nodejs

This comment has been minimized.

Copy link
@outdooricon

outdooricon Jun 29, 2015

Author Contributor

This is unrelated to this pr. I'd recommend creating a separate issue about this.

}

Expand Down
11 changes: 10 additions & 1 deletion test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('Runner', function(){
runner.fail(test, err);
})

it('should emit a the error when failed with an Error', function(done){
it('should emit a the error when failed with an Error instance', function(done){
var test = {}, err = new Error('an error message');
runner.on('fail', function(test, err){
err.message.should.equal('an error message');
Expand All @@ -238,6 +238,15 @@ describe('Runner', function(){
runner.fail(test, err);
})

it('should emit the error when failed with an Error-like object', function(done){
var test = {}, err = {message: 'an error message'};
runner.on('fail', function(test, err){
err.message.should.equal('an error message');
done();
});
runner.fail(test, err);
})

it('should emit a helpful message when failed with an Object', function(done){
var test = {}, err = { x: 1 };
runner.on('fail', function(test, err){
Expand Down

0 comments on commit 3fcca2e

Please sign in to comment.