// example.jsx import { h, Fragment, render, mount, ref, nextTick, mountCallback, } from '@/index'; const testChangeRef = ref void)>(null); let unmount1Count = 0; let unmount2Count = 0; const Depth2 = mount(() => { mountCallback(() => { console.log('MOUNT - Depth2'); return () => { unmount2Count += 1; console.log('UNMOUNT - Depth2'); }; }); return () => (
depth2
); }); const Depth1 = mount(() => { mountCallback(() => { console.log('MOUNT - Depth1'); return () => { unmount1Count += 1; console.log('UNMOUNT - Depth1'); }; }); return () => (
depth1
); }); const TestRoot = mount(renew => { let isShow = true; const toggle = () => { isShow = !isShow; renew(); }; testChangeRef.value = toggle; return () => (
{isShow && (
)}
); }); const Root = ; const testWrap = document.getElementById('root') || document.createElement('div'); render(Root, testWrap); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('All child components of the element being unmounted must have their unmount callbacks fired.', () => { expect(testWrap.outerHTML).toBe( '
depth1
depth2
depth1
depth2
' ); if (testChangeRef.value) { testChangeRef.value(); } nextTick().then(() => { expect(unmount1Count).toBe(2); expect(unmount2Count).toBe(2); }); }); }