Skip to content

Commit

Permalink
add vitest-when to mock
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Mar 19, 2024
1 parent 1af4de2 commit 4e04ff5
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import { when } from 'vitest-when'
import { it, describe, beforeEach, vi, expect } from 'vitest'
import { fireEvent, screen } from '@testing-library/react'
import { i18n } from '../../../i18n'
Expand All @@ -18,6 +19,7 @@ vi.mock('react-router-dom', async importOriginal => {
}
})

const RUN_ID = 'mockId'
const render = (
props: React.ComponentProps<typeof ProtocolSetupParameters>
) => {
Expand All @@ -33,9 +35,11 @@ describe('ProtocolSetupParameters', () => {
runId: 'mockId',
setSetupScreen: vi.fn(),
}
vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({
runTimeParameters: mockRunTimeParameterData,
} as any)
when(vi.mocked(useMostRecentCompletedAnalysis))
.calledWith(RUN_ID)
.thenReturn({
runTimeParameters: mockRunTimeParameterData,
} as any)
})
it('renders the parameters labels and mock data', () => {
render(props)
Expand Down

0 comments on commit 4e04ff5

Please sign in to comment.