// example.jsx import type { Renew } from '@/index'; import { h, Fragment, render, mount, ref, nextTick } from '@/index'; const testChangeRef = ref void)>(null); const testChangeRef2 = ref void)>(null); const Renew = mount((renew, _props) => { let count1 = 0; let count2 = 0; let count3 = 0; let count4 = 0; const el = ref(null); const change = () => { count1 += 1; count2 += 2; count3 += 3; count4 -= 1; renew(); }; const change2 = () => { count1 += 1; count2 += 9; count3 += 9; count4 -= 9; renew(); }; testChangeRef.value = change; testChangeRef2.value = change2; return () => (
  • count1: {count1}
  • count2: {count2}
  • count3: {count3}
  • count4: {count4}
  • ); }); const testWrap = document.getElementById('root') || document.createElement('div'); render(, testWrap); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('In some cases, if another event is caught, the previous event should be canceled and work fine.', () => { expect(testWrap.outerHTML).toBe( '
  • count1: 0
  • count2: 0
  • count3: 0
  • count4: 0
  • ' ); if (testChangeRef.value) { testChangeRef.value(); } nextTick().then(() => { expect(testWrap.outerHTML).toBe( '
  • count1: 1
  • count2: 2
  • count3: 3
  • count4: -1
  • ' ); if (testChangeRef2.value) { testChangeRef2.value(); } nextTick().then(() => { expect(testWrap.outerHTML).toBe( '
  • count1: 2
  • count2: 11
  • count3: 12
  • count4: -10
  • ' ); }); }); }); }