Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/Operation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
1 change: 1 addition & 0 deletions tests/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
32 changes: 32 additions & 0 deletions tests/node/tests/Operation.mjs
Original file line number Diff line number Diff line change
@@ -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/);
}),
]);