From 9f7a6ef06158b4753327e17fbde0cbe5841d2975 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 28 Oct 2017 10:05:28 -0700 Subject: [PATCH] Check truthiness of toThrowError args, not arg count This enables some useful simplifications at the cost of making it impossible (for now) to expect a function to throw an error with a falsy message. [#20622765] --- lib/jasmine-core/jasmine.js | 14 +++++++------- src/core/matchers/toThrowError.js | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index cd744f21..1976a797 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -3755,18 +3755,18 @@ getJasmineRequireObj().toThrowError = function(j$) { var expected = null, errorType = null; - if (arguments.length == 2) { - expected = arguments[1]; - if (isAnErrorType(expected)) { - errorType = expected; - expected = null; - } - } else if (arguments.length > 2) { + if (arguments[2]) { errorType = arguments[1]; expected = arguments[2]; if (!isAnErrorType(errorType)) { throw new Error(getErrorMsg('Expected error type is not an Error.')); } + } else if (arguments[1]) { + expected = arguments[1]; + if (isAnErrorType(expected)) { + errorType = expected; + expected = null; + } } if (expected && !isStringOrRegExp(expected)) { diff --git a/src/core/matchers/toThrowError.js b/src/core/matchers/toThrowError.js index ef809e35..7cdc1d9f 100644 --- a/src/core/matchers/toThrowError.js +++ b/src/core/matchers/toThrowError.js @@ -71,18 +71,18 @@ getJasmineRequireObj().toThrowError = function(j$) { var expected = null, errorType = null; - if (arguments.length == 2) { - expected = arguments[1]; - if (isAnErrorType(expected)) { - errorType = expected; - expected = null; - } - } else if (arguments.length > 2) { + if (arguments[2]) { errorType = arguments[1]; expected = arguments[2]; if (!isAnErrorType(errorType)) { throw new Error(getErrorMsg('Expected error type is not an Error.')); } + } else if (arguments[1]) { + expected = arguments[1]; + if (isAnErrorType(expected)) { + errorType = expected; + expected = null; + } } if (expected && !isStringOrRegExp(expected)) {