File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
packages/compiler-core/__tests__/transforms Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -1224,4 +1224,55 @@ describe('compiler: element transform', () => {
12241224 isBlock : false
12251225 } )
12261226 } )
1227+
1228+ describe ( '<KeepAlive> multiple children' , ( ) => {
1229+
1230+ function checkWarning (
1231+ template : string ,
1232+ shouldWarn : boolean ,
1233+ message = '<KeepAlive> expects exactly one child component.'
1234+ ) {
1235+ const spy = jest . fn ( )
1236+
1237+ parseWithBind ( template . trim ( ) , {
1238+ onError : err => {
1239+ spy ( err . message )
1240+ }
1241+ } )
1242+
1243+ if ( shouldWarn ) expect ( spy ) . toHaveBeenCalledWith ( message )
1244+ else expect ( spy ) . not . toHaveBeenCalled ( )
1245+ }
1246+
1247+ test ( 'does not warn if has one children' , ( ) => {
1248+ checkWarning (
1249+ `<KeepAlive>
1250+ <component :is="activeComponent"/>
1251+ </KeepAlive>` ,
1252+ false
1253+ )
1254+ } )
1255+
1256+ test ( 'warn if has multiple children' , ( ) => {
1257+ checkWarning (
1258+ `<KeepAlive>
1259+ <component :is="activeComponent"/>
1260+ <component :is="activeComponent2"/>
1261+ </KeepAlive>` ,
1262+ true
1263+ )
1264+ } )
1265+
1266+ test ( 'should ignore comments' , ( ) => {
1267+ expect ( baseCompile (
1268+ `<KeepAlive>
1269+ <!--this should be ignored -->
1270+ <component :is="activeComponent"/>
1271+ <!--this should be ignored -->
1272+ </KeepAlive>` ,
1273+ { prefixIdentifiers : true }
1274+ ) . code ) . toMatchSnapshot ( )
1275+ } )
1276+ } )
1277+
12271278} )
You can’t perform that action at this time.
0 commit comments