Skip to content

Commit

Permalink
fix useHistory mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Mar 4, 2024
1 parent 379af0a commit 793843b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<typeof ReactRouterDom>()
const actual = await importOriginal<typeof useHistory>()
return {
...reactRouterDom,
useHistory: () => ({ push: mockPush } as any),
...actual,
useHistory: () => ({ goBack: mockGoBack }),
}
})

Expand Down

0 comments on commit 793843b

Please sign in to comment.