Merge e73a83ac519f4d34c9d16b07d6a473a875e8f16a into b435acc6b4e9fecee17bc1f12fc0d6c071f1f449

This commit is contained in:
Adam Hassan 2026-08-05 16:03:39 -07:00 committed by GitHub
commit 2678a31cac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 1 deletions

View File

@ -244,7 +244,12 @@ class Operation {
set ingValues(ingValues) { set ingValues(ingValues) {
ingValues.forEach((val, i) => { ingValues.forEach((val, i) => {
try { try {
this._ingList[i].value = val; const ingredient = this._ingList[i],
value = ingredient.type === "number" && Number.isNaN(val) ?
ingredient.defaultValue :
val;
ingredient.value = value;
} catch (err) { } catch (err) {
throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`); throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`);
} }

View File

@ -21,6 +21,7 @@ import "./tests/operations.mjs";
import "./tests/PGP.mjs"; import "./tests/PGP.mjs";
import "./tests/File.mjs"; import "./tests/File.mjs";
import "./tests/Dish.mjs"; import "./tests/Dish.mjs";
import "./tests/Operation.mjs";
import "./tests/NodeDish.mjs"; import "./tests/NodeDish.mjs";
import "./tests/Utils.mjs"; import "./tests/Utils.mjs";
import "./tests/Categories.mjs"; import "./tests/Categories.mjs";

View File

@ -0,0 +1,32 @@
import TestRegister from "../../lib/TestRegister.mjs";
import Operation from "../../../src/core/Operation.mjs";
import it from "../../node/assertionHandler.mjs";
import assert from "assert";
TestRegister.addApiTests([
it("Operation - NaN number ingredients should use their default value", () => {
const operation = new Operation();
operation.args = [{
name: "Offset",
type: "number",
value: 0
}];
operation.ingValues = [NaN];
assert.deepStrictEqual(operation.ingValues, [0]);
}),
it("Operation - invalid number strings should still throw", () => {
const operation = new Operation();
operation.args = [{
name: "Offset",
type: "number",
value: 0
}];
assert.throws(() => {
operation.ingValues = ["NaN"];
}, /Invalid ingredient value\. Not a number: NaN/);
}),
]);