Refactor Suite#addExpectationResult to use named arguments

This commit is contained in:
Steve Gravrock
2025-09-21 09:05:00 -07:00
parent 4a36ece65b
commit 4020da25a4
2 changed files with 36 additions and 38 deletions

View File

@@ -10742,25 +10742,28 @@ getJasmineRequireObj().Suite = function(j$) {
this.onLateError(new Error(msg)); this.onLateError(new Error(msg));
} }
addExpectationResult() { addExpectationResult(passed, data) {
if (isFailure(arguments)) { if (passed) {
const data = arguments[1]; // Passed expectations are accepted for compatibility with
const expectationResult = j$.buildExpectationResult(data); // Spec#addExpectationResult, but aren't recorded.
return;
}
if (this.reportedDone) { const expectationResult = j$.buildExpectationResult(data);
this.onLateError(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
// TODO: refactor so that we don't need to override cached status if (this.reportedDone) {
if (this.result.status) { this.onLateError(expectationResult);
this.result.status = 'failed'; } 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) { if (this.#throwOnExpectationFailure) {
throw new j$.errors.ExpectationFailed(); throw new j$.errors.ExpectationFailed();
}
} }
} }
@@ -10857,10 +10860,6 @@ getJasmineRequireObj().Suite = function(j$) {
} }
} }
function isFailure(args) {
return !args[0];
}
return Suite; return Suite;
}; };

View File

@@ -220,25 +220,28 @@ getJasmineRequireObj().Suite = function(j$) {
this.onLateError(new Error(msg)); this.onLateError(new Error(msg));
} }
addExpectationResult() { addExpectationResult(passed, data) {
if (isFailure(arguments)) { if (passed) {
const data = arguments[1]; // Passed expectations are accepted for compatibility with
const expectationResult = j$.buildExpectationResult(data); // Spec#addExpectationResult, but aren't recorded.
return;
}
if (this.reportedDone) { const expectationResult = j$.buildExpectationResult(data);
this.onLateError(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
// TODO: refactor so that we don't need to override cached status if (this.reportedDone) {
if (this.result.status) { this.onLateError(expectationResult);
this.result.status = 'failed'; } 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) { if (this.#throwOnExpectationFailure) {
throw new j$.errors.ExpectationFailed(); throw new j$.errors.ExpectationFailed();
}
} }
} }
@@ -335,9 +338,5 @@ getJasmineRequireObj().Suite = function(j$) {
} }
} }
function isFailure(args) {
return !args[0];
}
return Suite; return Suite;
}; };