File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
tests/custom-elements/html Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,11 @@ export default class CustomElementRegistry {
278
278
return undefined ;
279
279
}
280
280
281
+ getName ( constructor : ElementConstructor ) : string | null {
282
+ const definition = this . _constructorToDefinition . get ( constructor ) ;
283
+ return definition ? definition . localName : null ;
284
+ }
285
+
281
286
whenDefined ( localName : string ) : Promise < void > {
282
287
if ( ! Utilities . isValidCustomElementName ( localName ) ) {
283
288
return Promise . reject (
@@ -363,4 +368,6 @@ CustomElementRegistry.prototype['polyfillDefineLazy'] =
363
368
CustomElementRegistry . prototype . polyfillDefineLazy ;
364
369
CustomElementRegistry . prototype [ 'polyfillWrapFlushCallback' ] =
365
370
CustomElementRegistry . prototype . polyfillWrapFlushCallback ;
371
+ CustomElementRegistry . prototype [ 'getName' ] =
372
+ CustomElementRegistry . prototype . getName ;
366
373
/* eslint-enable no-self-assign */
Original file line number Diff line number Diff line change 209
209
} ) ;
210
210
} ) ;
211
211
212
+ suite ( 'getName' , function ( ) {
213
+ test ( 'returns the local name for a defined custom element constructor' , function ( ) {
214
+ class XGetName extends HTMLElement { }
215
+ customElements . define ( 'x-get-name' , XGetName ) ;
216
+
217
+ var name = customElements . getName ( XGetName ) ;
218
+ assert . equal ( name , 'x-get-name' ) ;
219
+ } ) ;
220
+
221
+ test ( 'returns null for an undefined custom element constructor' , function ( ) {
222
+ class XUndefinedElement extends HTMLElement { }
223
+
224
+ var name = customElements . getName ( XUndefinedElement ) ;
225
+ assert . isNull ( name ) ;
226
+ } ) ;
227
+ } ) ;
228
+
212
229
suite ( 'whenDefined' , function ( ) {
213
230
test ( 'resolves when a tag is defined' , function ( ) {
214
231
var promise = customElements
You can’t perform that action at this time.
0 commit comments