import { h, render, mount, Fragment, ref, nextTick } from 'lithent'; import { store } from '@/index'; const testChangeRef1 = ref void)>(null); const testChangeRef2 = ref void)>(null); const testChangeRef3 = ref void)>(null); const assignShardStore = store<{ count1: number; count2: number; count3: number; }>({ count1: 0, count2: 0, count3: 0, }); const Component = mount(renew => { const shardStore = assignShardStore(renew, store => [ store.count1, store.count3, ]); const changeCount1 = () => { shardStore.count1 += 1; }; const changeCount2 = () => { shardStore.count2 += 1; }; const changeCount3 = () => { shardStore.count3 += 1; }; testChangeRef1.value = changeCount1; testChangeRef2.value = changeCount2; testChangeRef3.value = changeCount3; return () => ( ); }); document.body.innerHTML = `
123
`; const testbad = document.createElement('div'); testbad.id = 'root'; testbad.innerHTML = '123'; const testWrap = (document.getElementById('root') as HTMLElement) || document.createElement('div'); render( , testWrap, testWrap.querySelector('span:nth-of-type(2)') as HTMLElement ); render( , testWrap, testWrap.querySelector('span:nth-of-type(3)') as HTMLElement ); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('Even if you specify an observer function when assigning from a helper/store, you must be able to reference the value.', () => { expect(testWrap.outerHTML).toBe( '
123
' ); }); it('If the subscription array has no values, you should not detect a value change.', () => { if (testChangeRef2.value) { testChangeRef2.value(); testChangeRef2.value(); } nextTick().then(() => { expect(testWrap.outerHTML).toBe( '
123
' ); }); }); it('If the subscription array has values, we need to detect changes.', () => { if (testChangeRef1.value) { testChangeRef1.value(); testChangeRef1.value(); testChangeRef1.value(); } nextTick().then(() => { expect(testWrap.outerHTML).toBe( '
123
' ); }); }); }