From 4020da25a4ca7562d111c902b60d5108c80a4923 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sun, 21 Sep 2025 09:05:00 -0700 Subject: [PATCH] Refactor Suite#addExpectationResult to use named arguments --- lib/jasmine-core/jasmine.js | 37 ++++++++++++++++++------------------- src/core/Suite.js | 37 ++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index b518aa8a..d02dd1be 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -10742,25 +10742,28 @@ getJasmineRequireObj().Suite = function(j$) { this.onLateError(new Error(msg)); } - addExpectationResult() { - if (isFailure(arguments)) { - const data = arguments[1]; - const expectationResult = j$.buildExpectationResult(data); + addExpectationResult(passed, data) { + if (passed) { + // Passed expectations are accepted for compatibility with + // Spec#addExpectationResult, but aren't recorded. + return; + } - if (this.reportedDone) { - this.onLateError(expectationResult); - } else { - this.result.failedExpectations.push(expectationResult); + const expectationResult = j$.buildExpectationResult(data); - // TODO: refactor so that we don't need to override cached status - if (this.result.status) { - this.result.status = 'failed'; - } + if (this.reportedDone) { + this.onLateError(expectationResult); + } else { + this.result.failedExpectations.push(expectationResult); + + // TODO: refactor so that we don't need to override cached status + if (this.result.status) { + this.result.status = 'failed'; } + } - if (this.#throwOnExpectationFailure) { - throw new j$.errors.ExpectationFailed(); - } + if (this.#throwOnExpectationFailure) { + throw new j$.errors.ExpectationFailed(); } } @@ -10857,10 +10860,6 @@ getJasmineRequireObj().Suite = function(j$) { } } - function isFailure(args) { - return !args[0]; - } - return Suite; }; diff --git a/src/core/Suite.js b/src/core/Suite.js index fbbeca1a..58e226f4 100644 --- a/src/core/Suite.js +++ b/src/core/Suite.js @@ -220,25 +220,28 @@ getJasmineRequireObj().Suite = function(j$) { this.onLateError(new Error(msg)); } - addExpectationResult() { - if (isFailure(arguments)) { - const data = arguments[1]; - const expectationResult = j$.buildExpectationResult(data); + addExpectationResult(passed, data) { + if (passed) { + // Passed expectations are accepted for compatibility with + // Spec#addExpectationResult, but aren't recorded. + return; + } - if (this.reportedDone) { - this.onLateError(expectationResult); - } else { - this.result.failedExpectations.push(expectationResult); + const expectationResult = j$.buildExpectationResult(data); - // TODO: refactor so that we don't need to override cached status - if (this.result.status) { - this.result.status = 'failed'; - } + if (this.reportedDone) { + this.onLateError(expectationResult); + } else { + this.result.failedExpectations.push(expectationResult); + + // TODO: refactor so that we don't need to override cached status + if (this.result.status) { + this.result.status = 'failed'; } + } - if (this.#throwOnExpectationFailure) { - throw new j$.errors.ExpectationFailed(); - } + if (this.#throwOnExpectationFailure) { + throw new j$.errors.ExpectationFailed(); } } @@ -335,9 +338,5 @@ getJasmineRequireObj().Suite = function(j$) { } } - function isFailure(args) { - return !args[0]; - } - return Suite; };