From 00bd6d8198815883a6453173dcbe0c8b17f9f336 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 30 Jun 2020 10:42:17 -0500 Subject: [PATCH 1/2] Add failing test for autocomplete with dynamic type This will cause axe to throw an error like: > TypeError: Cannot read property 'replace' of null I believe that the problem might be related to getLiteralPropValue returning `null` instead of `undefined` for dynamic props. --- __tests__/src/rules/autocomplete-valid-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/__tests__/src/rules/autocomplete-valid-test.js b/__tests__/src/rules/autocomplete-valid-test.js index da7b39a1a..020c583f1 100644 --- a/__tests__/src/rules/autocomplete-valid-test.js +++ b/__tests__/src/rules/autocomplete-valid-test.js @@ -54,6 +54,7 @@ ruleTester.run('autocomplete-valid', rule, { { code: ';', errors: invalidAutocomplete }, { code: ';', errors: invalidAutocomplete }, { code: ';', errors: invalidAutocomplete, options: [{ inputComponents: ['Bar'] }] }, + { code: ';', errors: invalidAutocomplete }, // FAILED "autocomplete-appropriate" { code: ';', errors: inappropriateAutocomplete }, From 2c47f0ada2d71273a7d4adea856ad14636caaf42 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 30 Jun 2020 10:22:16 -0700 Subject: [PATCH 2/2] [Fix] `autocomplete-valid`: workaround for axe not being able to handle `null` --- src/rules/autocomplete-valid.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rules/autocomplete-valid.js b/src/rules/autocomplete-valid.js index 9b3f5a091..a1c1e1c7c 100644 --- a/src/rules/autocomplete-valid.js +++ b/src/rules/autocomplete-valid.js @@ -35,12 +35,13 @@ module.exports = { return; } + const type = getLiteralPropValue(getProp(node.attributes, 'type')); const { violations } = runVirtualRule('autocomplete-valid', { nodeName: 'input', attributes: { autocomplete, // Which autocomplete is valid depends on the input type - type: getLiteralPropValue(getProp(node.attributes, 'type')), + type: type === null ? undefined : type, }, });