From 93f87c10783e3d76f1dec667779aedffcae33a39 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 11 Dec 2023 18:59:25 +0100 Subject: test(hooks): fix not wrapped in act error in Jest test --- src/utils/hooks/use-redirection/use-redirection.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/utils/hooks/use-redirection/use-redirection.test.ts') diff --git a/src/utils/hooks/use-redirection/use-redirection.test.ts b/src/utils/hooks/use-redirection/use-redirection.test.ts index c14ac4c..0dae949 100644 --- a/src/utils/hooks/use-redirection/use-redirection.test.ts +++ b/src/utils/hooks/use-redirection/use-redirection.test.ts @@ -1,5 +1,5 @@ import { describe, it } from '@jest/globals'; -import { renderHook } from '@testing-library/react'; +import { act, renderHook } from '@testing-library/react'; import nextRouterMock from 'next-router-mock'; import { MemoryRouterProvider } from 'next-router-mock/MemoryRouterProvider'; import { useRedirection } from './use-redirection'; @@ -12,7 +12,7 @@ describe('useRedirection', () => { // eslint-disable-next-line @typescript-eslint/no-magic-numbers expect.assertions(2); - await nextRouterMock.push('/initial-path'); + await act(async () => nextRouterMock.push('/initial-path')); expect(nextRouterMock.asPath).toBe(initialPath); @@ -30,7 +30,7 @@ describe('useRedirection', () => { // eslint-disable-next-line @typescript-eslint/no-magic-numbers expect.assertions(2); - await nextRouterMock.push('/initial-path'); + await act(async () => nextRouterMock.push('/initial-path')); expect(nextRouterMock.asPath).toBe(initialPath); @@ -54,7 +54,7 @@ describe('useRedirection', () => { // eslint-disable-next-line @typescript-eslint/no-magic-numbers expect.assertions(3); - await nextRouterMock.push('/initial-path'); + await act(async () => nextRouterMock.push('/initial-path')); expect(nextRouterMock.asPath).toBe(paths.initial); @@ -71,7 +71,7 @@ describe('useRedirection', () => { expect(nextRouterMock.asPath).toBe(paths.initial); - await nextRouterMock.push(paths.matching); + await act(async () => nextRouterMock.push(paths.matching)); rerender(); -- cgit v1.2.3