Merge e73a83ac519f4d34c9d16b07d6a473a875e8f16a into b435acc6b4e9fecee17bc1f12fc0d6c071f1f449
This commit is contained in:
commit
2678a31cac
@ -244,7 +244,12 @@ class Operation {
|
||||
set ingValues(ingValues) {
|
||||
ingValues.forEach((val, i) => {
|
||||
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) {
|
||||
throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`);
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import "./tests/operations.mjs";
|
||||
import "./tests/PGP.mjs";
|
||||
import "./tests/File.mjs";
|
||||
import "./tests/Dish.mjs";
|
||||
import "./tests/Operation.mjs";
|
||||
import "./tests/NodeDish.mjs";
|
||||
import "./tests/Utils.mjs";
|
||||
import "./tests/Categories.mjs";
|
||||
|
||||
32
tests/node/tests/Operation.mjs
Normal file
32
tests/node/tests/Operation.mjs
Normal 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/);
|
||||
}),
|
||||
]);
|
||||
Loading…
x
Reference in New Issue
Block a user