From 793843bc0ab9b88d95972e8a6a6bb54c3bba8278 Mon Sep 17 00:00:00 2001 From: koji Date: Mon, 4 Mar 2024 13:10:04 -0500 Subject: [PATCH] fix useHistory mocking --- .../DeckConfigurationDiscardChangesModal.tsx | 2 +- .../DeckConfigurationDiscardChangesModal.test.tsx | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/organisms/DeviceDetailsDeckConfiguration/DeckConfigurationDiscardChangesModal.tsx b/app/src/organisms/DeviceDetailsDeckConfiguration/DeckConfigurationDiscardChangesModal.tsx index d672bcd9098..1d956a507d9 100644 --- a/app/src/organisms/DeviceDetailsDeckConfiguration/DeckConfigurationDiscardChangesModal.tsx +++ b/app/src/organisms/DeviceDetailsDeckConfiguration/DeckConfigurationDiscardChangesModal.tsx @@ -23,10 +23,10 @@ export function DeckConfigurationDiscardChangesModal({ setShowConfirmationModal, }: DeckConfigurationDiscardChangesModalProps): JSX.Element { const { t } = useTranslation('device_details') + const history = useHistory() const modalHeader: ModalHeaderBaseProps = { title: t('changes_will_be_lost'), } - const history = useHistory() const handleDiscard = (): void => { setShowConfirmationModal(false) diff --git a/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeckConfigurationDiscardChangesModal.test.tsx b/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeckConfigurationDiscardChangesModal.test.tsx index b51e17ce500..33b112e1043 100644 --- a/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeckConfigurationDiscardChangesModal.test.tsx +++ b/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeckConfigurationDiscardChangesModal.test.tsx @@ -1,22 +1,20 @@ import * as React from 'react' import { fireEvent, screen } from '@testing-library/react' import { describe, it, beforeEach, vi, expect } from 'vitest' +import { useHistory } from 'react-router-dom' import { renderWithProviders } from '../../../__testing-utils__' import { i18n } from '../../../i18n' import { DeckConfigurationDiscardChangesModal } from '../DeckConfigurationDiscardChangesModal' -import type * as ReactRouterDom from 'react-router-dom' - const mockFunc = vi.fn() const mockGoBack = vi.fn() -const mockPush = vi.fn() vi.mock('react-router-dom', async importOriginal => { - const reactRouterDom = await importOriginal() + const actual = await importOriginal() return { - ...reactRouterDom, - useHistory: () => ({ push: mockPush } as any), + ...actual, + useHistory: () => ({ goBack: mockGoBack }), } })