Skip to content

Commit

Permalink
throw error if only one argument supplied to eq
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Nov 11, 2021
1 parent cacb2b8 commit 543ef13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/test.only-one-arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const test = require("../index.js");

test("error", ({ eq }) => {
eq(1);
});
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const complete = [];

const run = async ({ name, cb, caller }) => {
let savedActual, savedExpected;
const eq = (actual, expected) => {
const eq = function (actual, expected) {
if (arguments.length === 1) {
throw new Error("you only supplied one argument");
}
savedActual = actual;
savedExpected = expected;
if (deepStrictEqual) {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ t("node ./examples/test.queue.js", "\x1B[32msuccess: first\x1B[0m\n\x1B[32msucce
t("node ./examples/test.filename.js", "\x1B[33mskipped: invalid filename\x1B[39m\n\x1B[32msuccess: valid filename\x1B[0m\n");

t("node ./examples/test.dir.js", "\x1B[33mskipped: invalid dir\x1B[39m\n\x1B[32msuccess: valid dir\x1B[0m\n");

const cmd2 = "node ./examples/test.only-one-arg.js";
const log2 = $(cmd2).trim().replace(/\n/g, "");
assert.strictEqual(log2.includes("you only supplied one argument"), true);

0 comments on commit 543ef13

Please sign in to comment.