Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross-frame compatible Error checking for fail #1758

Merged
merged 1 commit into from
Jun 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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