@@ -112,7 +112,6 @@ describe( 'Unique Selector Tests', () =>
112
112
expect ( uniqueSelector ) . to . equal ( 'span' ) ;
113
113
} ) ;
114
114
115
-
116
115
it ( 'Tag' , ( ) =>
117
116
{
118
117
$ ( 'body' ) . append ( '<div class="test5"><span></span></div><div class="test5"><span></span></div>' ) ;
@@ -129,6 +128,74 @@ describe( 'Unique Selector Tests', () =>
129
128
expect ( uniqueSelector ) . to . equal ( 'a' ) ;
130
129
} ) ;
131
130
131
+ it ( 'Tag - fallback to nodeName' , ( ) =>
132
+ {
133
+ $ ( 'body' ) . append ( `
134
+ <div class="test2">
135
+ <form action="" method="get">
136
+ <div class="form-example">
137
+ <label for="name">Enter your name: </label>
138
+ <input type="text" name="name" id="tagName" required />
139
+ </div>
140
+ </form>
141
+ </div>
142
+ ` ) ;
143
+
144
+ const formNode = $ ( 'form' ) . get ( 0 ) ;
145
+
146
+ // JSDOM doesn't actually exhibit this behavior;
147
+ // forcing the test to behave as a browser does.
148
+ Object . defineProperty ( formNode , 'tagName' , {
149
+ get : ( ) => {
150
+ return $ ( 'input#tagName' ) . get ( 0 ) ;
151
+ }
152
+ } )
153
+
154
+ expect ( typeof formNode . tagName ) . to . not . equal ( 'string' )
155
+
156
+ const uniqueSelector = unique ( formNode ) ;
157
+ // nodeName === 'form'
158
+ expect ( uniqueSelector ) . to . equal ( 'form' ) ;
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
+
132
199
it ( 'Attributes' , ( ) =>
133
200
{
134
201
$ ( 'body' ) . append ( '<div class="test5" test="5"></div>' ) ;
0 commit comments