@@ -778,14 +778,37 @@ test('should clean up subscriptions after calling the returned cleanup function'
778778 const fixture = new ElementFixture ( ) ;
779779
780780 const spies = {
781- cleanupSpy : false ,
781+ cleanup : false ,
782782 } ;
783783
784784 const { cleanup } = await render ( fixture . host , < CleanupComponent spies = { spies } /> ) ;
785785
786786 cleanup ( ) ;
787787
788- assert . equal ( spies . cleanupSpy , true ) ;
788+ assert . equal ( spies . cleanup , true ) ;
789+ } ) ;
790+
791+ test ( 'should clean up nested subscriptions after calling the returned cleanup function' , async ( ) => {
792+ const fixture = new ElementFixture ( ) ;
793+
794+ const spies = {
795+ parentCleanup : false ,
796+ cleanup : false ,
797+ slottedCleanup : false ,
798+ } ;
799+
800+ const { cleanup } = await render (
801+ fixture . host ,
802+ < ParentCleanupComponent spies = { spies } >
803+ < SlottedCleanupComponent spies = { spies } />
804+ </ ParentCleanupComponent >
805+ ) ;
806+
807+ cleanup ( ) ;
808+
809+ assert . equal ( spies . parentCleanup , true ) ;
810+ assert . equal ( spies . cleanup , true ) ;
811+ assert . equal ( spies . slottedCleanup , true ) ;
789812} ) ;
790813
791814async function expectRendered ( fixture : ElementFixture , expected : string ) {
@@ -1045,16 +1068,56 @@ export const Hooks = component$(() => {
10451068
10461069//////////////////////////////////////////////////////////////////////////////////////////
10471070
1048- export const CleanupComponent = component$ ( ( props : { spies : { cleanupSpy : boolean } } ) => {
1071+ interface CleanupProps {
1072+ spies : {
1073+ parentCleanup ?: boolean ;
1074+ cleanup ?: boolean ;
1075+ slottedCleanup ?: boolean ;
1076+ } ;
1077+ }
1078+
1079+ export const ParentCleanupComponent = component$ ( ( props : CleanupProps ) => {
10491080 useTask$ ( ( { cleanup } ) => {
10501081 cleanup ( ( ) => {
1051- props . spies . cleanupSpy = true ;
1082+ props . spies . parentCleanup = true ;
1083+ } ) ;
1084+ } ) ;
1085+
1086+ return (
1087+ < div >
1088+ < div id = "parent-cleanup" > true</ div >
1089+ < CleanupComponent spies = { props . spies } >
1090+ < Slot />
1091+ </ CleanupComponent >
1092+ </ div >
1093+ ) ;
1094+ } ) ;
1095+
1096+ export const CleanupComponent = component$ ( ( props : CleanupProps ) => {
1097+ useTask$ ( ( { cleanup } ) => {
1098+ cleanup ( ( ) => {
1099+ props . spies . cleanup = true ;
10521100 } ) ;
10531101 } ) ;
10541102
10551103 return (
10561104 < div >
10571105 < div id = "cleanup" > true</ div >
1106+ < Slot />
1107+ </ div >
1108+ ) ;
1109+ } ) ;
1110+
1111+ export const SlottedCleanupComponent = component$ ( ( props : CleanupProps ) => {
1112+ useTask$ ( ( { cleanup } ) => {
1113+ cleanup ( ( ) => {
1114+ props . spies . slottedCleanup = true ;
1115+ } ) ;
1116+ } ) ;
1117+
1118+ return (
1119+ < div >
1120+ < div id = "slotted-cleanup" > true</ div >
10581121 </ div >
10591122 ) ;
10601123} ) ;
0 commit comments