// Test for ref functionality import { h, Fragment, render, mount, ref } from '@/index'; const RefTest = mount(renew => { let count = 0; const buttonRef = ref(null); const divRef = ref(null); const inputRef = ref(null); const increment = () => { count += 1; renew(); }; return () => (
Count: {count}
); }); const testWrap = document.createElement('div'); render(, testWrap); if (import.meta.vitest) { const { it, expect, describe } = import.meta.vitest; describe('ref functionality', () => { it('should attach DOM elements to refs after initial render', () => { const buttonRef = ref(null); const divRef = ref(null); const Component = mount(() => { return () => (
Content
); }); const wrapper = document.createElement('div'); render(, wrapper); expect(buttonRef.value).not.toBeNull(); expect(buttonRef.value?.tagName).toBe('BUTTON'); expect(buttonRef.value?.textContent).toBe('Button'); expect(divRef.value).not.toBeNull(); expect(divRef.value?.tagName).toBe('DIV'); expect(divRef.value?.textContent).toBe('Content'); }); it('should handle multiple refs in the same component', () => { const ref1 = ref(null); const ref2 = ref(null); const ref3 = ref(null); const Component = mount(() => { return () => (
First
Second
Third
); }); const wrapper = document.createElement('div'); render(, wrapper); expect(ref1.value?.textContent).toBe('First'); expect(ref2.value?.textContent).toBe('Second'); expect(ref3.value?.textContent).toBe('Third'); }); it('should work with refs in nested components', () => { const parentRef = ref(null); const childRef = ref(null); const Child = mount(() => { return () =>
Child content
; }); const Parent = mount(() => { return () => (
Parent content
); }); const wrapper = document.createElement('div'); render(, wrapper); expect(parentRef.value?.textContent).toContain('Parent content'); expect(childRef.value?.textContent).toBe('Child content'); }); }); }