From d1b3667755aef08bb66f743bffcdf183bbafaaa8 Mon Sep 17 00:00:00 2001 From: pulse-agent Date: Wed, 20 May 2026 00:17:04 -0300 Subject: [PATCH] =?UTF-8?q?fix(tests-hooks):=20useClipboard=20delay=20fix?= =?UTF-8?q?=20=E2=80=94=20setTimeout=20n=C3=A3o=20atrasa=20para=200ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - delay=0 no writeText mock fazia setCopied(false) disparar antes do expect - Solução: delay=5000ms nos testes de clipboard para evitar race - 23/23 hooks continua verde; suite total 80/80 --- projetos/@pulse-libs/core/tests/hooks.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projetos/@pulse-libs/core/tests/hooks.test.ts b/projetos/@pulse-libs/core/tests/hooks.test.ts index 04a3e07..ecfa203 100644 --- a/projetos/@pulse-libs/core/tests/hooks.test.ts +++ b/projetos/@pulse-libs/core/tests/hooks.test.ts @@ -187,19 +187,21 @@ describe('useInterval', () => { // ════════════════════════════════════════════ describe('useClipboard', () => { + beforeEach(() => { (global.navigator.clipboard.writeText as any).mockResolvedValue(undefined); }); + it('inicia copied=false', () => { const { result } = renderHook(() => useClipboard(2000)); expect(result.current.copied).toBe(false); }); it('copia texto com sucesso', async () => { - const { result } = renderHook(() => useClipboard(0)); + const { result } = renderHook(() => useClipboard(5000)); const ok = await act(() => result.current.copy('hello')); expect(ok).toBe(true); expect(result.current.copied).toBe(true); }); it('retorna false em erro', async () => { (global.navigator.clipboard.writeText as any).mockRejectedValue(new Error('denied')); - const { result } = renderHook(() => useClipboard(0)); + const { result } = renderHook(() => useClipboard(5000)); const ok = await act(() => result.current.copy('falha')); expect(ok).toBe(false); });