From ca7799a525c158cd8f4b4f8bc37d622aa557a6c7 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 7 Nov 2023 16:56:17 -0600 Subject: [PATCH] refactor testIncludes for conciseness Co-authored-by: Richard Gibson --- proposals/53:kread-start/core-eval-support.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/proposals/53:kread-start/core-eval-support.js b/proposals/53:kread-start/core-eval-support.js index 61910552..d27d76e5 100644 --- a/proposals/53:kread-start/core-eval-support.js +++ b/proposals/53:kread-start/core-eval-support.js @@ -36,21 +36,20 @@ export const getContractInfo = async (path, io = {}) => { return m.fromCapData({ body, slots }); }; -// not really core-eval related +/** + * Asserts that `haystack` includes `needle` (or when `sense` is false, that it + * does not), providing pretty output in the case of failure. + * + * @param {import('ava').ExecutionContext} t + * @param {unknown} needle + * @param {unknown[]} haystack + * @param {string} label + * @param {boolean} [sense] true to assert inclusion; false for exclusion + * @returns {void} + */ export const testIncludes = (t, needle, haystack, label, sense = true) => { - t.log(needle, sense ? 'in' : 'not in', haystack.length, label, '?'); - const check = sense ? t.deepEqual : t.notDeepEqual; - if (sense) { - t.deepEqual( - haystack.filter(c => c === needle), - [needle], - ); - } else { - t.deepEqual( - haystack.filter(c => c === needle), - [], - ); - } + const matches = haystack.filter(c => Object.is(c, needle)); + t.deepEqual(matches, sense ? [needle] : [], label); }; /**