@@ -119,6 +119,107 @@ describe('Document', () => {
119
119
} ) ;
120
120
} ) ;
121
121
122
+ describe ( '.getElementsByTagName' , ( ) => {
123
+ it ( 'can find all descendants matching the given qualifiedName' , ( ) => {
124
+ const root = document . appendChild ( document . createElement ( 'root' ) ) ;
125
+ const e1 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
126
+ const e2 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
127
+ const other = root . appendChild ( document . createElementNS ( null , 'other' ) ) ;
128
+ const e3 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
129
+ const e4 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
130
+ const e5 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
131
+ const e6 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
132
+
133
+ expect ( document . getElementsByTagName ( 'root' ) ) . toEqual ( [ root ] ) ;
134
+ expect ( document . getElementsByTagName ( 'pre:elem' ) ) . toEqual ( [ e1 , e2 , e3 , e4 ] ) ;
135
+ expect ( document . getElementsByTagName ( 'other' ) ) . toEqual ( [ other ] ) ;
136
+ expect ( document . getElementsByTagName ( 'x:elem' ) ) . toEqual ( [ e5 , e6 ] ) ;
137
+ } ) ;
138
+
139
+ it ( 'can find all descendant elements using the special name "*"' , ( ) => {
140
+ const root = document . appendChild ( document . createElement ( 'root' ) ) ;
141
+ const e1 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
142
+ const e2 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
143
+ const other = root . appendChild ( document . createElementNS ( null , 'other' ) ) ;
144
+ const e3 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
145
+ const e4 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
146
+ const e5 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
147
+ const e6 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
148
+
149
+ expect ( document . getElementsByTagName ( '*' ) ) . toEqual ( [
150
+ root ,
151
+ e1 ,
152
+ e2 ,
153
+ other ,
154
+ e3 ,
155
+ e4 ,
156
+ e5 ,
157
+ e6 ,
158
+ ] ) ;
159
+ } ) ;
160
+ } ) ;
161
+
162
+ describe ( '.getElementsByTagNameNS' , ( ) => {
163
+ it ( 'can find all descendants matching the given namespace and localName' , ( ) => {
164
+ const root = document . appendChild ( document . createElement ( 'root' ) ) ;
165
+ const e1 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
166
+ const e2 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
167
+ const other = root . appendChild ( document . createElementNS ( null , 'other' ) ) ;
168
+ const e3 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
169
+ const e4 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
170
+ const e5 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
171
+ const e6 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
172
+
173
+ expect ( document . getElementsByTagNameNS ( null , 'root' ) ) . toEqual ( [ root ] ) ;
174
+ expect ( document . getElementsByTagNameNS ( 'zoinks' , 'root' ) ) . toEqual ( [ ] ) ;
175
+ expect ( document . getElementsByTagNameNS ( 'namespace' , 'elem' ) ) . toEqual ( [ e1 , e2 ] ) ;
176
+ expect ( document . getElementsByTagNameNS ( 'otherns' , 'elem' ) ) . toEqual ( [ e3 , e4 , e5 , e6 ] ) ;
177
+ expect ( document . getElementsByTagNameNS ( '' , 'other' ) ) . toEqual ( [ other ] ) ;
178
+ } ) ;
179
+
180
+ it ( 'can find all descendant elements using the special namespace "*"' , ( ) => {
181
+ const root = document . appendChild ( document . createElement ( 'root' ) ) ;
182
+ const e1 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
183
+ const e2 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
184
+ const other = root . appendChild ( document . createElementNS ( null , 'other' ) ) ;
185
+ const e3 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
186
+ const e4 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
187
+ const e5 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
188
+ const e6 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
189
+
190
+ expect ( document . getElementsByTagNameNS ( '*' , 'root' ) ) . toEqual ( [ root ] ) ;
191
+ expect ( document . getElementsByTagNameNS ( '*' , 'elem' ) ) . toEqual ( [ e1 , e2 , e3 , e4 , e5 , e6 ] ) ;
192
+ expect ( document . getElementsByTagNameNS ( '*' , 'other' ) ) . toEqual ( [ other ] ) ;
193
+ } ) ;
194
+
195
+ it ( 'can find all descendant elements using the special localName "*"' , ( ) => {
196
+ const root = document . appendChild ( document . createElement ( 'root' ) ) ;
197
+ const e1 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
198
+ const e2 = root . appendChild ( document . createElementNS ( 'namespace' , 'pre:elem' ) ) ;
199
+ const other = root . appendChild ( document . createElementNS ( null , 'other' ) ) ;
200
+ const e3 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
201
+ const e4 = other . appendChild ( document . createElementNS ( 'otherns' , 'pre:elem' ) ) ;
202
+ const e5 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
203
+ const e6 = other . appendChild ( document . createElementNS ( 'otherns' , 'x:elem' ) ) ;
204
+
205
+ expect ( document . getElementsByTagNameNS ( null , '*' ) ) . toEqual ( [ root , other ] ) ;
206
+ expect ( document . getElementsByTagNameNS ( '' , '*' ) ) . toEqual ( [ root , other ] ) ;
207
+ expect ( document . getElementsByTagNameNS ( 'zoinks' , '*' ) ) . toEqual ( [ ] ) ;
208
+ expect ( document . getElementsByTagNameNS ( 'namespace' , '*' ) ) . toEqual ( [ e1 , e2 ] ) ;
209
+ expect ( document . getElementsByTagNameNS ( 'otherns' , '*' ) ) . toEqual ( [ e3 , e4 , e5 , e6 ] ) ;
210
+ expect ( document . getElementsByTagNameNS ( '*' , '*' ) ) . toEqual ( [
211
+ root ,
212
+ e1 ,
213
+ e2 ,
214
+ other ,
215
+ e3 ,
216
+ e4 ,
217
+ e5 ,
218
+ e6 ,
219
+ ] ) ;
220
+ } ) ;
221
+ } ) ;
222
+
122
223
describe ( '.cloneNode' , ( ) => {
123
224
beforeEach ( ( ) => {
124
225
document . appendChild ( document . createElement ( 'root' ) ) ;
0 commit comments