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 {
278278 return undefined ;
279279 }
280280
281+ getName ( constructor : ElementConstructor ) : string | null {
282+ const definition = this . _constructorToDefinition . get ( constructor ) ;
283+ return definition ? definition . localName : null ;
284+ }
285+
281286 whenDefined ( localName : string ) : Promise < void > {
282287 if ( ! Utilities . isValidCustomElementName ( localName ) ) {
283288 return Promise . reject (
@@ -363,4 +368,6 @@ CustomElementRegistry.prototype['polyfillDefineLazy'] =
363368 CustomElementRegistry . prototype . polyfillDefineLazy ;
364369CustomElementRegistry . prototype [ 'polyfillWrapFlushCallback' ] =
365370 CustomElementRegistry . prototype . polyfillWrapFlushCallback ;
371+ CustomElementRegistry . prototype [ 'getName' ] =
372+ CustomElementRegistry . prototype . getName ;
366373/* eslint-enable no-self-assign */
Original file line number Diff line number Diff line change 209209 } ) ;
210210 } ) ;
211211
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+
212229 suite ( 'whenDefined' , function ( ) {
213230 test ( 'resolves when a tag is defined' , function ( ) {
214231 var promise = customElements
You can’t perform that action at this time.
0 commit comments