@@ -128,7 +128,7 @@ describe( 'Unique Selector Tests', () =>
128
128
expect ( uniqueSelector ) . to . equal ( 'a' ) ;
129
129
} ) ;
130
130
131
- it ( 'Tag - filtered due to property override ' , ( ) =>
131
+ it ( 'Tag - fallback to nodeName ' , ( ) =>
132
132
{
133
133
$ ( 'body' ) . append ( `
134
134
<div class="test2">
@@ -154,9 +154,48 @@ describe( 'Unique Selector Tests', () =>
154
154
expect ( typeof formNode . tagName ) . to . not . equal ( 'string' )
155
155
156
156
const uniqueSelector = unique ( formNode ) ;
157
- expect ( uniqueSelector ) . to . equal ( '.test2 > :nth-child(1)' ) ;
157
+ // nodeName === 'form'
158
+ expect ( uniqueSelector ) . to . equal ( 'form' ) ;
158
159
} ) ;
159
160
161
+ it ( 'Tag - ignored due to property override' , ( ) =>
162
+ {
163
+ $ ( 'body' ) . append ( `
164
+ <div class="test2">
165
+ <form action="" method="get">
166
+ <div class="form-example">
167
+ <label for="name">Enter your name: </label>
168
+ <input type="text" name="name" id="tagName" required />
169
+ </div>
170
+ </form>
171
+ </div>
172
+ ` ) ;
173
+
174
+ const formNode = $ ( 'form' ) . get ( 0 ) ;
175
+
176
+ // JSDOM doesn't actually exhibit this behavior;
177
+ // forcing the test to behave as a browser does.
178
+ Object . defineProperty ( formNode , 'tagName' , {
179
+ get : ( ) => {
180
+ return $ ( 'input#tagName' ) . get ( 0 ) ;
181
+ }
182
+ } )
183
+ Object . defineProperty ( formNode , 'nodeName' , {
184
+ get : ( ) => {
185
+ return $ ( 'input#tagName' ) . get ( 0 ) ;
186
+ }
187
+ } )
188
+
189
+ expect ( typeof formNode . tagName ) . to . not . equal ( 'string' )
190
+ expect ( typeof formNode . nodeName ) . to . not . equal ( 'string' )
191
+
192
+ const uniqueSelector = unique ( formNode ) ;
193
+ // with nodeName overridden, the isElement check will fail
194
+ // and the wildcard selector is returned for that element.
195
+ // This really shouldn't happen in practice.
196
+ expect ( uniqueSelector ) . to . equal ( '.test2 > *' ) ;
197
+ } ) ;
198
+
160
199
it ( 'Attributes' , ( ) =>
161
200
{
162
201
$ ( 'body' ) . append ( '<div class="test5" test="5"></div>' ) ;
0 commit comments