@@ -18,16 +18,28 @@ describe(`Rules: ${ruleId}`, () => {
18
18
)
19
19
} )
20
20
21
- it ( 'Duplicate values in data attribute should result in an error' , ( ) => {
21
+ it ( 'Duplicate values in id attribute should NOT result in an error with default config' , ( ) => {
22
+ const code = '<div id="section1 main section1">Test</div>'
23
+ const messages = HTMLHint . verify ( code , ruleOptions )
24
+ expect ( messages . length ) . toBe ( 0 )
25
+ } )
26
+
27
+ it ( 'Duplicate values in role attribute should NOT result in an error with default config' , ( ) => {
28
+ const code = '<div role="button navigation button">Test</div>'
29
+ const messages = HTMLHint . verify ( code , ruleOptions )
30
+ expect ( messages . length ) . toBe ( 0 )
31
+ } )
32
+
33
+ it ( 'Duplicate values in name attribute should NOT result in an error with default config' , ( ) => {
34
+ const code = '<input name="username form1 username">'
35
+ const messages = HTMLHint . verify ( code , ruleOptions )
36
+ expect ( messages . length ) . toBe ( 0 )
37
+ } )
38
+
39
+ it ( 'Duplicate values in data attribute should not result in an error with default config' , ( ) => {
22
40
const code = '<span data-attributes="dark light dark">Test</span>'
23
41
const messages = HTMLHint . verify ( code , ruleOptions )
24
- expect ( messages . length ) . toBe ( 1 )
25
- expect ( messages [ 0 ] . rule . id ) . toBe ( ruleId )
26
- expect ( messages [ 0 ] . line ) . toBe ( 1 )
27
- expect ( messages [ 0 ] . col ) . toBe ( 6 )
28
- expect ( messages [ 0 ] . message ) . toBe (
29
- 'Duplicate value [ dark ] was found in attribute [ data-attributes ].'
30
- )
42
+ expect ( messages . length ) . toBe ( 0 )
31
43
} )
32
44
33
45
it ( 'No duplicate values should not result in an error' , ( ) => {
@@ -65,58 +77,65 @@ describe(`Rules: ${ruleId}`, () => {
65
77
)
66
78
} )
67
79
68
- it ( 'SVG elements should be skipped entirely' , ( ) => {
69
- const code = '<svg class="icon icon icon" viewBox="0 0 24 24"></svg>'
70
- const messages = HTMLHint . verify ( code , ruleOptions )
71
- expect ( messages . length ) . toBe ( 0 )
72
- } )
73
-
74
- it ( 'Style attributes should be skipped entirely' , ( ) => {
80
+ it ( 'Angular directive attributes should not result in an error' , ( ) => {
75
81
const code =
76
- '<div style="width: 2rem; height: 2rem; width: 2rem; ">Test</div>'
82
+ '<div [ngClass]="\'btn btn\'" *ngIf="condition condition ">Test</div>'
77
83
const messages = HTMLHint . verify ( code , ruleOptions )
78
84
expect ( messages . length ) . toBe ( 0 )
79
85
} )
80
86
81
- it ( 'CSS media queries with commas should not be flagged as duplicates ' , ( ) => {
82
- const code =
83
- '<link rel="stylesheet" href="css/test.css" media="all and (-ms-high-contrast: active), (-ms-high-contrast: none) ">'
87
+ it ( 'Alt attributes with duplicate words should not result in an error ' , ( ) => {
88
+ // This has the word "a" repeated multiple times which would trigger an error if 'alt' was checked
89
+ const code = '<img src="image.jpg" alt="A cat and a dog and a ball ">'
84
90
const messages = HTMLHint . verify ( code , ruleOptions )
85
91
expect ( messages . length ) . toBe ( 0 )
86
92
} )
87
93
88
- it ( 'Media attribute with actual duplicates should be skipped' , ( ) => {
89
- const code =
90
- '<link rel="stylesheet" href="css/test.css" media="screen screen">'
91
- const messages = HTMLHint . verify ( code , ruleOptions )
92
- expect ( messages . length ) . toBe ( 0 )
93
- } )
94
+ it ( 'Custom attribute configuration should work as expected' , ( ) => {
95
+ const customOptions = { }
96
+ customOptions [ ruleId ] = [ 'data-test' , 'aria-label' ]
94
97
95
- it ( 'Content attribute should be skipped entirely' , ( ) => {
96
- const code =
97
- '<meta name="keywords" content="HTML, CSS, JavaScript, HTML, responsive design">'
98
- const messages = HTMLHint . verify ( code , ruleOptions )
99
- expect ( messages . length ) . toBe ( 0 )
100
- } )
98
+ // This should now trigger an error with our custom config
99
+ const code = '<div data-test="unit test unit">Test</div>'
100
+ const messages = HTMLHint . verify ( code , customOptions )
101
+ expect ( messages . length ) . toBe ( 1 )
102
+ expect ( messages [ 0 ] . rule . id ) . toBe ( ruleId )
103
+ expect ( messages [ 0 ] . message ) . toBe (
104
+ 'Duplicate value [ unit ] was found in attribute [ data-test ].'
105
+ )
101
106
102
- it ( 'Script src attribute should be skipped entirely' , ( ) => {
103
- const code =
104
- '<script src="data:text/javascript,window.analytics = window.analytics || function() { (window.analytics.q = window.analytics.q || []).push(arguments) }"></script>'
105
- const messages = HTMLHint . verify ( code , ruleOptions )
106
- expect ( messages . length ) . toBe ( 0 )
107
+ // Class should no longer be checked with custom config
108
+ const code2 = '<div class="btn primary btn">Test</div>'
109
+ const messages2 = HTMLHint . verify ( code2 , customOptions )
110
+ expect ( messages2 . length ) . toBe ( 0 )
107
111
} )
108
112
109
- it ( 'Sizes attribute should be skipped entirely' , ( ) => {
110
- const code =
111
- '<source type="" sizes="(min-width: 1rem) 1vw, (min-width: 2rem) 2vw" srcset="">'
112
- const messages = HTMLHint . verify ( code , ruleOptions )
113
- expect ( messages . length ) . toBe ( 0 )
114
- } )
113
+ it ( 'Extended custom configuration should work as expected' , ( ) => {
114
+ const extendedOptions = { }
115
+ extendedOptions [ ruleId ] = [ 'class' , 'id' , 'role' , 'name' ]
115
116
116
- it ( 'Event handler attributes should be skipped entirely' , ( ) => {
117
- const code =
118
- "<button onclick=\"trackEvent('click'); validateForm(); trackEvent('click');\">Submit</button>"
119
- const messages = HTMLHint . verify ( code , ruleOptions )
120
- expect ( messages . length ) . toBe ( 0 )
117
+ // Class should still be checked
118
+ const code1 = '<div class="btn primary btn">Test</div>'
119
+ const messages1 = HTMLHint . verify ( code1 , extendedOptions )
120
+ expect ( messages1 . length ) . toBe ( 1 )
121
+ expect ( messages1 [ 0 ] . message ) . toBe (
122
+ 'Duplicate value [ btn ] was found in attribute [ class ].'
123
+ )
124
+
125
+ // Id should now be checked
126
+ const code2 = '<div id="section1 main section1">Test</div>'
127
+ const messages2 = HTMLHint . verify ( code2 , extendedOptions )
128
+ expect ( messages2 . length ) . toBe ( 1 )
129
+ expect ( messages2 [ 0 ] . message ) . toBe (
130
+ 'Duplicate value [ section1 ] was found in attribute [ id ].'
131
+ )
132
+
133
+ // Role should now be checked
134
+ const code3 = '<div role="button navigation button">Test</div>'
135
+ const messages3 = HTMLHint . verify ( code3 , extendedOptions )
136
+ expect ( messages3 . length ) . toBe ( 1 )
137
+ expect ( messages3 [ 0 ] . message ) . toBe (
138
+ 'Duplicate value [ button ] was found in attribute [ role ].'
139
+ )
121
140
} )
122
141
} )
0 commit comments