From 543ef135fde6c5f578aaf674e901f7a692b75e79 Mon Sep 17 00:00:00 2001 From: DanielJDufour Date: Thu, 11 Nov 2021 17:02:05 -0500 Subject: [PATCH] throw error if only one argument supplied to eq --- examples/test.only-one-arg.js | 5 +++++ index.js | 5 ++++- test.js | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 examples/test.only-one-arg.js diff --git a/examples/test.only-one-arg.js b/examples/test.only-one-arg.js new file mode 100644 index 0000000..d677e8a --- /dev/null +++ b/examples/test.only-one-arg.js @@ -0,0 +1,5 @@ +const test = require("../index.js"); + +test("error", ({ eq }) => { + eq(1); +}); diff --git a/index.js b/index.js index 9f39b8f..ce8b932 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test.js b/test.js index 9cc09e3..df92c65 100644 --- a/test.js +++ b/test.js @@ -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);