UNPKG

@stackoverfloweth/vue-compositions

Version:

A collection of reusable vue compositions.

30 lines 1.03 kB
import { afterEach, vi, expect, describe, it } from 'vitest'; import { ref } from 'vue'; import { useDebouncedRef } from '../useDebouncedRef/useDebouncedRef'; afterEach(() => { vi.useRealTimers(); }); describe('useDebouncedRef', () => { it('it syncs the initial value', () => { const input = ref(1); const output = useDebouncedRef(input, 100); expect(output.value).toBe(1); }); it('it debounces updates to the value', async () => { vi.useFakeTimers(); const input = ref(1); const output = useDebouncedRef(input, 100); input.value = 2; expect(output.value).toBe(1); await vi.runAllTimersAsync(); expect(output.value).toBe(2); }); it('it syncs the debounced value back to the input', () => { vi.useFakeTimers(); const input = ref(1); const output = useDebouncedRef(input, 100); output.value = 2; expect(input.value).toBe(2); }); }); //# sourceMappingURL=useDebouncedRef.spec.js.map