From c1479acd17786a5acd33eed3bc71736f8cbee70e Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Mon, 12 Jan 2015 13:37:10 -0800 Subject: [PATCH] Fix `fail` specs for all browsers #734 --- spec/core/integration/EnvSpec.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index 4f60a4ff..0321a197 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -143,8 +143,7 @@ describe("Env integration", function() { it('explicitly fails a spec', function(done) { var env = new j$.Env(), - specDone = jasmine.createSpy('specDone'), - errorObj = new Error('error message'); + specDone = jasmine.createSpy('specDone'); env.addReporter({ specDone: specDone, @@ -167,7 +166,16 @@ describe("Env integration", function() { message: 'Failed: error message', stack: { asymmetricMatch: function(other) { - var firstLine = other.split('\n')[1]; + if (!other) { + // IE doesn't give us a stacktrace so just ignore it. + return true; + } + var split = other.split('\n'), + firstLine = split[0]; + if (firstLine.indexOf('error message') >= 0) { + // Chrome inserts the message and a newline before the first stacktrace line. + firstLine = split[1]; + } return firstLine.indexOf('EnvSpec') >= 0; } } @@ -187,7 +195,7 @@ describe("Env integration", function() { }); env.it('has a message and stack trace from an Error', function() { - env.fail(errorObj); + env.fail(new Error('error message')); }); });