import { h, Fragment, render, mount, ref, nextTick } from 'lithent'; import { store } from '@/hook/store'; const testChangeRef = ref void)>(null); const subscribe = store<{ count1: number; count2: number; count3: number }>({ count1: 1, count2: 1, count3: 1, }); let proxySubscribeChkValue: number = 0; const abortControl = new AbortController(); // @ts-ignore window.abort = abortControl; console.log(abortControl); const proxyFirst = subscribe( store => { proxySubscribeChkValue = store.count1; console.log(store); return abortControl.signal; }, store => [store.count1, store.count2] ); console.log(proxyFirst); // @ts-ignore window.proxyFirst = proxyFirst; const Component = mount(r => { const local = subscribe(r, store => [store.count3]); const click = () => { local.count1 += 1; local.count2 -= 1; local.count3 *= 2; }; testChangeRef.value = click; return () => ( <>
count1: {local.count1}
count2: {local.count2}
count3: {local.count3}
); }); const testWrap = document.getElementById('root') || document.createElement('div'); render(, testWrap); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('A DOM should be created that reflects the initial values of your store.', () => { expect(testWrap.outerHTML).toBe( '
count1: 1
count2: 1
count3: 1
' ); if (testChangeRef.value) { testChangeRef.value(); testChangeRef.value(); testChangeRef.value(); } }); it('You should see a DOM that reflects the changed store values.', () => { nextTick().then(() => { expect(testWrap.outerHTML).toBe( '
count1: 4
count2: -2
count3: 8
' ); }); }); it('abort test', () => { abortControl.abort(); proxyFirst.count1 = 999; nextTick().then(() => { expect(proxySubscribeChkValue).toBe(4); }); }); }