Skip to content

Commit

Permalink
Merge pull request #1758 from outdooricon/FixRunnerFail
Browse files Browse the repository at this point in the history
Add cross-frame compatible Error checking for fail
  • Loading branch information
danielstjules committed Jun 28, 2015
2 parents 44b0045 + 3fcca2e commit 3b02d83
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 :)');
}

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 3b02d83

Please sign in to comment.