@@ -195,39 +195,42 @@ suite('LitElement', () => {
195
195
assert . equal ( window [ 'litElementVersions' ] . length , 1 ) ;
196
196
} ) ;
197
197
198
- test ( 'event fired during rendering element can trigger an update' , async ( ) => {
199
- class E extends LitElement {
200
- connectedCallback ( ) {
201
- super . connectedCallback ( ) ;
202
- this . dispatchEvent ( new CustomEvent ( 'foo' , { bubbles : true , detail : 'foo' } ) ) ;
203
- }
204
- }
205
- customElements . define ( 'x-child-61012' , E ) ;
206
-
207
- class F extends LitElement {
208
-
209
- static get properties ( ) {
210
- return { foo : { type : String } } ;
211
- }
198
+ test (
199
+ 'event fired during rendering element can trigger an update' ,
200
+ async ( ) => {
201
+ class E extends LitElement {
202
+ connectedCallback ( ) {
203
+ super . connectedCallback ( ) ;
204
+ this . dispatchEvent (
205
+ new CustomEvent ( 'foo' , { bubbles : true , detail : 'foo' } ) ) ;
206
+ }
207
+ }
208
+ customElements . define ( 'x-child-61012' , E ) ;
212
209
213
- foo = '' ;
210
+ class F extends LitElement {
211
+ static get properties ( ) {
212
+ return { foo : { type : String } } ;
213
+ }
214
214
215
- render ( ) {
216
- return html `< x-child-61012 @foo =${ this . _handleFoo } > </ x-child-61012 > < span > ${ this . foo } </ span > ` ;
217
- }
215
+ foo = '' ;
218
216
219
- _handleFoo ( e : CustomEvent ) {
220
- this . foo = e . detail ;
221
- }
217
+ render ( ) {
218
+ return html `< x-child-61012 @foo =${
219
+ this . _handleFoo } > </ x-child-61012 > < span > ${ this . foo } </ span > `;
220
+ }
222
221
223
- }
222
+ _handleFoo ( e : CustomEvent ) {
223
+ this . foo = e . detail ;
224
+ }
225
+ }
224
226
225
- customElements . define ( generateElementName ( ) , F ) ;
226
- const el = new F ( ) ;
227
- container . appendChild ( el ) ;
228
- while ( ! ( await el . updateComplete ) ) { }
229
- assert . equal ( el . shadowRoot ! . textContent , 'foo' ) ;
230
- } ) ;
227
+ customElements . define ( generateElementName ( ) , F ) ;
228
+ const el = new F ( ) ;
229
+ container . appendChild ( el ) ;
230
+ while ( ! ( await el . updateComplete ) ) {
231
+ }
232
+ assert . equal ( el . shadowRoot ! . textContent , 'foo' ) ;
233
+ } ) ;
231
234
232
235
test (
233
236
'exceptions in `render` throw but do not prevent further updates' ,
@@ -266,4 +269,32 @@ suite('LitElement', () => {
266
269
assert . equal ( a . foo , 20 ) ;
267
270
assert . equal ( a . shadowRoot ! . textContent , '20' ) ;
268
271
} ) ;
272
+
273
+ test (
274
+ 'if `render` is unimplemented, do not overwrite renderRoot' , async ( ) => {
275
+ class A extends LitElement {
276
+ addedDom : HTMLElement | null = null ;
277
+ createRenderRoot ( ) {
278
+ return this ;
279
+ }
280
+ connectedCallback ( ) {
281
+ super . connectedCallback ( ) ;
282
+ this . addedDom = this . renderRoot . querySelector ( 'div' ) ;
283
+ }
284
+ }
285
+ customElements . define ( generateElementName ( ) , A ) ;
286
+ const a = new A ( ) ;
287
+ const testDom = document . createElement ( 'div' ) ;
288
+ a . appendChild ( testDom ) ;
289
+ container . appendChild ( a ) ;
290
+ await a . updateComplete ;
291
+ assert . equal (
292
+ a . addedDom ,
293
+ testDom ,
294
+ 'testDom should be found in connectedCallback' ) ;
295
+ assert . equal (
296
+ testDom . parentNode ,
297
+ a ,
298
+ 'testDom should be a child of the component' ) ;
299
+ } ) ;
269
300
} ) ;
0 commit comments