import { h, Fragment, render, mount, ref, nextTick } from 'lithent'; import { store } from '@/hook/store'; const testChangeRef = ref void)>(null); const subscribe = store(0); const subscribeArr = store([1]); let proxySubscribeChkValue = 0; const abortControl = new AbortController(); const proxyFirst = subscribe(store => { proxySubscribeChkValue = store.value; console.log(store); return abortControl.signal; }); console.log(proxyFirst); const Component = mount(r => { const local = subscribe(r, null, { cache: false }); const localArr = subscribeArr(r); const click = () => { local.value += 1; localArr.value = [...localArr.value, localArr.value.length + 1]; }; testChangeRef.value = click; return () => ( <>
value: {local.value}
{localArr.value.map(item => ( {item} ))} ); }); const testWrap = document.getElementById('root') || document.createElement('div'); render(, testWrap); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('If the value is not an object, it is expanded to value and processed.', () => { expect(testWrap.outerHTML).toBe( '
value: 0
1
' ); if (testChangeRef.value) { testChangeRef.value(); testChangeRef.value(); testChangeRef.value(); } }); it('If the value is not an object, the event operates normally and the value increases.', () => { nextTick().then(() => { expect(testWrap.outerHTML).toBe( '
value: 3
1234
' ); expect(proxySubscribeChkValue).toBe(3); }); }); }