import { h, Fragment, render, mount, ref, nextTick } from '@/index'; const testChangeRef = ref void)>(null); const Radio = mount(r => { let text = 'sara'; const handleInput = (event: InputEvent) => { text = (event.target as HTMLInputElement).value; r(); }; testChangeRef.value = (newText: string) => { text = newText; r(); }; return () => ( <> {' '} John {' '} Sara {' '} Tom ); }); const testWrap = document.getElementById('root') || document.createElement('div'); render(, testWrap); if (import.meta.vitest) { const { it, expect } = import.meta.vitest; it('You should see the initial value of the radio.', () => { expect(testWrap.outerHTML).toBe( '
John Sara Tom
' ); expect( ( Array.from( testWrap.querySelectorAll('input[name="checkname"]:checked') ) as HTMLFormElement[] ).map(item => item.value) ).toEqual(['sara']); }); it('The changed value should be reflected in the radio.', () => { if (testChangeRef.value) { testChangeRef.value('tom'); } nextTick().then(() => { expect( ( Array.from( testWrap.querySelectorAll('input[name="checkname"]:checked') ) as HTMLFormElement[] ).map(item => item.value) ).toEqual(['tom']); }); }); }