From 0b4a9edff864a3e192d3aea3600766d07b8dc8cd Mon Sep 17 00:00:00 2001 From: Valentin Hermann Date: Wed, 8 Jan 2020 10:55:14 +0100 Subject: [PATCH] Added some tests and modified the source code instead of the build product --- spec/core/StackTraceSpec.js | 42 +++++++++++++++++++++++++++++++++++++ src/core/StackTrace.js | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/spec/core/StackTraceSpec.js b/spec/core/StackTraceSpec.js index 9cbffe33..d041c8e7 100644 --- a/spec/core/StackTraceSpec.js +++ b/spec/core/StackTraceSpec.js @@ -213,4 +213,46 @@ describe('StackTrace', function() { } ]); }); + + it('consideres different types of errors', function() { + var error = { + message: 'nope', + stack: + 'TypeError: nope\n' + + ' at UserContext. (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' + + ' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)' + }; + + var result = new jasmineUnderTest.StackTrace(error); + + expect(result.message).toEqual('TypeError: nope'); + expect(result.frames).toEqual([ + { + raw: + ' at UserContext. (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)', + func: 'UserContext.', + file: 'http://localhost:8888/__spec__/core/UtilSpec.js', + line: 115 + }, + { + raw: + ' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)', + func: 'QueueRunner.run', + file: 'http://localhost:8888/__jasmine__/jasmine.js', + line: 4320 + } + ]); + + var no_error = { + message: 'nope', + stack: + 'Type Error: nope\n' + + ' at UserContext. (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' + + ' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)' + }; + + var result_no_error = new jasmineUnderTest.StackTrace(no_error); + + expect(result_no_error.message).not.toEqual(jasmine.anything()); + }); }); diff --git a/src/core/StackTrace.js b/src/core/StackTrace.js index 3382751d..44db4ff1 100644 --- a/src/core/StackTrace.js +++ b/src/core/StackTrace.js @@ -104,7 +104,7 @@ getJasmineRequireObj().StackTrace = function(j$) { } function messagePrefixLength(message, stackLines) { - if (!stackLines[0].match(/^Error/)) { + if (!stackLines[0].match(/^\w*Error/)) { return 0; }