From 76dd06958a62596d44b0e23822e003f8dde2bd8e Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Sun, 20 Aug 2023 09:29:06 -0400 Subject: [PATCH 1/4] new tests for multiple testAttributes --- lib/rules/onClick.js | 3 ++- tests/lib/rules/anchor.js | 5 ++++- tests/lib/rules/button.js | 7 +++++-- tests/lib/rules/input.js | 5 ++++- tests/lib/rules/onChange.js | 21 ++++++++++++--------- tests/lib/rules/onClick.js | 9 ++++++++- tests/lib/rules/onKeyDown.js | 7 +++++-- tests/lib/rules/onKeyUp.js | 7 +++++-- tests/lib/rules/onSubmit.js | 7 +++++-- 9 files changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/rules/onClick.js b/lib/rules/onClick.js index 1a93b7b..ada29cd 100644 --- a/lib/rules/onClick.js +++ b/lib/rules/onClick.js @@ -47,7 +47,8 @@ module.exports = { const { nanoid } = require('nanoid'); const suggestedId = nanoid(); const namePositionEnd = node.name.range[1]; - const attributeText = `${ testAttribute }="${ suggestedId }"`; + const singleTestAttribute = Array.isArray(testAttribute) ? testAttribute[0] : testAttribute; + const attributeText = `${ singleTestAttribute }="${ suggestedId }"`; const start = namePositionEnd - 1; const end = start + 1; diff --git a/tests/lib/rules/anchor.js b/tests/lib/rules/anchor.js index cb4c116..0b16c09 100644 --- a/tests/lib/rules/anchor.js +++ b/tests/lib/rules/anchor.js @@ -28,7 +28,9 @@ ruleTester.run('anchor', rule, { { code: `Bar` }, { code: `` }, { code: `` }, - { code: `` } + { code: `` }, + { code: `Foo`, options: ["always", {"testAttribute": "testId"}] }, + { code: `Foo`, options: ["always", {"testAttribute": ["testId", "data-testid"]}] } ].map(parserOptionsMapper), invalid: [ @@ -41,5 +43,6 @@ ruleTester.run('anchor', rule, { { code: '', errors: [anchorError] }, { code: '', errors: [anchorError] }, { code: '', errors: [anchorError] }, + { code: `Foo`, options: ["always", {"testAttribute": ["testId", "data-testid"]}], errors: [getError(anchor.message, ["testId", "data-testid"])] } ].map(parserOptionsMapper) }); diff --git a/tests/lib/rules/button.js b/tests/lib/rules/button.js index 25538a6..0c24b15 100644 --- a/tests/lib/rules/button.js +++ b/tests/lib/rules/button.js @@ -27,7 +27,9 @@ ruleTester.run('button', rule, { { code: `` }, { code: ``, options: ["warn", {htmlOnly: true}] } + { code: ``, options: ["warn", {htmlOnly: true}] }, + { code: ``, options: ["warn", {htmlOnly: true}] }, - { code: ``, options: ['warn', { htmlOnly: true }] }, + { code: `