From aeb840fbc8dc9c7c68fd0252d5dce6f5e5c56af1 Mon Sep 17 00:00:00 2001 From: Kevin Brewer Date: Fri, 23 Oct 2020 11:35:15 -0700 Subject: [PATCH] fix: prevent error when "options" are not passed to checkForViolations (#6) --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index cffc899..b871095 100644 --- a/index.js +++ b/index.js @@ -53,20 +53,22 @@ const createReport = violations => { * @param options * @returns {Promise<{error: *}|{error: *, results: {passes: *, violations: * }}>} */ -const axeCheck = async (t, context, options={}) => { +const axeCheck = (t, context, options = { rules: {} }) => { try { // skipping the "document-title" rule as there is an issue with testcafe // being unable to find the title of a page inside the tag. options = options["rules"]['document-title'] = {'enabled': false}; - return await runAxe.with({ boundTestRun: t })(context, options); - } catch (e) { - return { error: e }; + return runAxe.with({ boundTestRun: t })(context, options); + } catch (error) { + return Promise.resolve({ error }); } }; const checkForViolations = async (t, context, options) => { - const { results } = await axeCheck(t, context, options); + const { error, results } = await axeCheck(t, context, options); + await t.expect(error).notOk(); + await t.expect(results.violations.length === 0).ok(createReport(results.violations)); }