import { h, Fragment, render, mount, ref, nextTick } from '@/index'; const testChangeRef = ref void)>(null); const Loop = mount(function (renew) { let list: { key: number; value: string }[] = [ { key: 4, value: '4' }, { key: 5, value: '5' }, { key: 6, value: '6' }, { key: 7, value: '7' }, ]; const handle = () => { list = [ { key: 7, value: 'seven' }, { key: 6, value: 'six' }, { key: 5, value: 'five' }, { key: 4, value: 'four' }, ]; renew(); }; testChangeRef.value = () => { handle(); }; return () => ( {list.map(item => (
{item.value}
))}
); }); document.body.innerHTML = ''; const testWrap = document.getElementById('list-root') as HTMLElement; render(, testWrap, document.getElementById('nextTarget')); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it("Tests if 'Lithent' correctly handles changes to the virtual DOM element when there is a loop element mixed between the real and virtual DOM elements.", () => { expect(testWrap.outerHTML).toBe( '' ); }); it('It should only update the virtualDOM elements well, without changing the existing Real DOM elements.', () => { if (testChangeRef.value) { testChangeRef.value(); } nextTick().then(() => { expect(testWrap.outerHTML).toBe( '' ); }); }); }