22 * @fileoverview Requires test attribute data-test-id on elements with the onClick property.
33 * @author David Calhoun
44 */
5- const {
6- errors,
7- defaultRuleSchema,
8- defaults
9- } = require ( '../constants' ) ;
5+ const { errors, defaultRuleSchema, defaults } = require ( '../constants' ) ;
106
11- const {
12- getError,
13- shouldBypass
14- } = require ( '../utils' ) ;
7+ const { getError, shouldBypass } = require ( '../utils' ) ;
158
169module . exports = {
1710 meta : {
@@ -25,7 +18,7 @@ module.exports = {
2518 schema : defaultRuleSchema
2619 } ,
2720
28- create : function ( context ) {
21+ create : function ( context ) {
2922 const options = context . options [ 1 ] || { } ;
3023 const testAttribute = options . testAttribute || defaults . testAttribute ;
3124
@@ -47,15 +40,13 @@ module.exports = {
4740 const { nanoid } = require ( 'nanoid' ) ;
4841 const suggestedId = nanoid ( ) ;
4942 const namePositionEnd = node . name . range [ 1 ] ;
50- const attributeText = `${ testAttribute } ="${ suggestedId } "` ;
43+ const singleTestAttribute = Array . isArray ( testAttribute ) ? testAttribute [ 0 ] : testAttribute ;
44+ const attributeText = `${ singleTestAttribute } ="${ suggestedId } "` ;
5145 const start = namePositionEnd - 1 ;
5246 const end = start + 1 ;
5347
54- return fixer . insertTextAfterRange (
55- [ start , end ] ,
56- ` ${ attributeText } `
57- ) ;
58- } ,
48+ return fixer . insertTextAfterRange ( [ start , end ] , ` ${ attributeText } ` ) ;
49+ }
5950 } ) ;
6051 }
6152 } ;
0 commit comments