@@ -337,7 +337,7 @@ describe('attribute fallthrough', () => {
337
337
it ( 'should warn when fallthrough fails on non-single-root' , ( ) => {
338
338
const Parent = {
339
339
render ( ) {
340
- return h ( Child , { foo : 1 , class : 'parent' } )
340
+ return h ( Child , { foo : 1 , class : 'parent' , onBar : ( ) => { } } )
341
341
}
342
342
}
343
343
@@ -353,12 +353,13 @@ describe('attribute fallthrough', () => {
353
353
render ( h ( Parent ) , root )
354
354
355
355
expect ( `Extraneous non-props attributes (class)` ) . toHaveBeenWarned ( )
356
+ expect ( `Extraneous non-emits event listeners` ) . toHaveBeenWarned ( )
356
357
} )
357
358
358
359
it ( 'should not warn when $attrs is used during render' , ( ) => {
359
360
const Parent = {
360
361
render ( ) {
361
- return h ( Child , { foo : 1 , class : 'parent' } )
362
+ return h ( Child , { foo : 1 , class : 'parent' , onBar : ( ) => { } } )
362
363
}
363
364
}
364
365
@@ -374,13 +375,15 @@ describe('attribute fallthrough', () => {
374
375
render ( h ( Parent ) , root )
375
376
376
377
expect ( `Extraneous non-props attributes` ) . not . toHaveBeenWarned ( )
378
+ expect ( `Extraneous non-emits event listeners` ) . not . toHaveBeenWarned ( )
379
+
377
380
expect ( root . innerHTML ) . toBe ( `<div></div><div class="parent"></div>` )
378
381
} )
379
382
380
383
it ( 'should not warn when context.attrs is used during render' , ( ) => {
381
384
const Parent = {
382
385
render ( ) {
383
- return h ( Child , { foo : 1 , class : 'parent' } )
386
+ return h ( Child , { foo : 1 , class : 'parent' , onBar : ( ) => { } } )
384
387
}
385
388
}
386
389
@@ -396,9 +399,72 @@ describe('attribute fallthrough', () => {
396
399
render ( h ( Parent ) , root )
397
400
398
401
expect ( `Extraneous non-props attributes` ) . not . toHaveBeenWarned ( )
402
+ expect ( `Extraneous non-emits event listeners` ) . not . toHaveBeenWarned ( )
403
+
399
404
expect ( root . innerHTML ) . toBe ( `<div></div><div class="parent"></div>` )
400
405
} )
401
406
407
+ it ( 'should not warn when context.attrs is used during render (functional)' , ( ) => {
408
+ const Parent = {
409
+ render ( ) {
410
+ return h ( Child , { foo : 1 , class : 'parent' , onBar : ( ) => { } } )
411
+ }
412
+ }
413
+
414
+ const Child : FunctionalComponent = ( _ , { attrs } ) => [
415
+ h ( 'div' ) ,
416
+ h ( 'div' , attrs )
417
+ ]
418
+
419
+ Child . props = [ 'foo' ]
420
+
421
+ const root = document . createElement ( 'div' )
422
+ document . body . appendChild ( root )
423
+ render ( h ( Parent ) , root )
424
+
425
+ expect ( `Extraneous non-props attributes` ) . not . toHaveBeenWarned ( )
426
+ expect ( `Extraneous non-emits event listeners` ) . not . toHaveBeenWarned ( )
427
+ expect ( root . innerHTML ) . toBe ( `<div></div><div class="parent"></div>` )
428
+ } )
429
+
430
+ it ( 'should not warn when functional component has optional props' , ( ) => {
431
+ const Parent = {
432
+ render ( ) {
433
+ return h ( Child , { foo : 1 , class : 'parent' , onBar : ( ) => { } } )
434
+ }
435
+ }
436
+
437
+ const Child = ( props : any ) => [ h ( 'div' ) , h ( 'div' , { class : props . class } ) ]
438
+
439
+ const root = document . createElement ( 'div' )
440
+ document . body . appendChild ( root )
441
+ render ( h ( Parent ) , root )
442
+
443
+ expect ( `Extraneous non-props attributes` ) . not . toHaveBeenWarned ( )
444
+ expect ( `Extraneous non-emits event listeners` ) . not . toHaveBeenWarned ( )
445
+ expect ( root . innerHTML ) . toBe ( `<div></div><div class="parent"></div>` )
446
+ } )
447
+
448
+ it ( 'should warn when functional component has props and does not use attrs' , ( ) => {
449
+ const Parent = {
450
+ render ( ) {
451
+ return h ( Child , { foo : 1 , class : 'parent' , onBar : ( ) => { } } )
452
+ }
453
+ }
454
+
455
+ const Child : FunctionalComponent = ( ) => [ h ( 'div' ) , h ( 'div' ) ]
456
+
457
+ Child . props = [ 'foo' ]
458
+
459
+ const root = document . createElement ( 'div' )
460
+ document . body . appendChild ( root )
461
+ render ( h ( Parent ) , root )
462
+
463
+ expect ( `Extraneous non-props attributes` ) . toHaveBeenWarned ( )
464
+ expect ( `Extraneous non-emits event listeners` ) . toHaveBeenWarned ( )
465
+ expect ( root . innerHTML ) . toBe ( `<div></div><div></div>` )
466
+ } )
467
+
402
468
// #677
403
469
it ( 'should update merged dynamic attrs on optimized child root' , async ( ) => {
404
470
const aria = ref ( 'true' )
0 commit comments