Skip to content

Commit 1b23c98

Browse files
committed
migrate organisms/devices/hooks to vitest
1 parent e728cf7 commit 1b23c98

37 files changed

+693
-992
lines changed

app/src/organisms/Devices/hooks/__tests__/useAttachedModules.test.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resetAllWhenMocks } from 'jest-when'
1+
import { vi, it, expect, describe } from 'vitest'
22
import { UseQueryResult } from 'react-query'
33
import { renderHook } from '@testing-library/react'
44
import { mockModulesResponse } from '@opentrons/api-client'
@@ -7,18 +7,14 @@ import { useAttachedModules } from '..'
77

88
import type { Modules } from '@opentrons/api-client'
99

10-
jest.mock('@opentrons/react-api-client')
10+
vi.mock('@opentrons/react-api-client')
1111

12-
const mockUseModulesQuery = useModulesQuery as jest.MockedFunction<
12+
const mockUseModulesQuery = useModulesQuery as vi.MockedFunction<
1313
typeof useModulesQuery
1414
>
1515

1616
describe('useAttachedModules hook', () => {
1717
let wrapper: React.FunctionComponent<{ children: React.ReactNode }>
18-
afterEach(() => {
19-
resetAllWhenMocks()
20-
jest.resetAllMocks()
21-
})
2218

2319
it('returns attached modules', () => {
2420
mockUseModulesQuery.mockReturnValue({

app/src/organisms/Devices/hooks/__tests__/useAttachedPipetteCalibrations.test.tsx

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
2-
import { when, resetAllWhenMocks } from 'jest-when'
2+
import { when } from 'vitest-when'
3+
import { vi, it, expect, describe, beforeEach } from 'vitest'
34
import { Provider } from 'react-redux'
45
import { createStore, Store } from 'redux'
56
import { renderHook } from '@testing-library/react'
@@ -20,23 +21,14 @@ import {
2021
} from '../../../../redux/calibration/tip-length/__fixtures__'
2122

2223
import { useAttachedPipetteCalibrations } from '..'
24+
import type { State } from '../../../../redux/types'
2325

24-
jest.mock('@opentrons/react-api-client')
25-
jest.mock('../../../../redux/calibration')
26-
jest.mock('../../../../redux/pipettes')
27-
jest.mock('../../../../redux/robot-api')
26+
vi.mock('@opentrons/react-api-client')
27+
vi.mock('../../../../redux/calibration')
28+
vi.mock('../../../../redux/pipettes')
29+
vi.mock('../../../../redux/robot-api')
2830

29-
const mockUsePipettesQuery = usePipettesQuery as jest.MockedFunction<
30-
typeof usePipettesQuery
31-
>
32-
const mockUseAllPipetteOffsetCalibrationsQuery = useAllPipetteOffsetCalibrationsQuery as jest.MockedFunction<
33-
typeof useAllPipetteOffsetCalibrationsQuery
34-
>
35-
const mockUseAllTipLengthCalibrationsQuery = useAllTipLengthCalibrationsQuery as jest.MockedFunction<
36-
typeof useAllTipLengthCalibrationsQuery
37-
>
38-
39-
const store: Store<any> = createStore(jest.fn(), {})
31+
const store: Store<State> = createStore(state => state, {})
4032

4133
const PIPETTE_CALIBRATIONS = {
4234
left: {
@@ -61,15 +53,11 @@ describe('useAttachedPipetteCalibrations hook', () => {
6153
</Provider>
6254
)
6355
})
64-
afterEach(() => {
65-
resetAllWhenMocks()
66-
jest.resetAllMocks()
67-
})
6856

6957
it('returns attached pipette calibrations when given a robot name', () => {
70-
when(mockUsePipettesQuery)
58+
when(vi.mocked(usePipettesQuery))
7159
.calledWith({}, {})
72-
.mockReturnValue({
60+
.thenReturn({
7361
data: {
7462
left: {
7563
id: mockPipetteOffsetCalibration1.pipette,
@@ -89,16 +77,16 @@ describe('useAttachedPipetteCalibrations hook', () => {
8977
},
9078
},
9179
} as any)
92-
when(mockUseAllPipetteOffsetCalibrationsQuery)
80+
when(vi.mocked(useAllPipetteOffsetCalibrationsQuery))
9381
.calledWith()
94-
.mockReturnValue({
82+
.thenReturn({
9583
data: {
9684
data: [mockPipetteOffsetCalibration1, mockPipetteOffsetCalibration2],
9785
},
9886
} as any)
99-
when(mockUseAllTipLengthCalibrationsQuery)
87+
when(vi.mocked(useAllTipLengthCalibrationsQuery))
10088
.calledWith()
101-
.mockReturnValue({
89+
.thenReturn({
10290
data: {
10391
data: [mockTipLengthCalibration1, mockTipLengthCalibration2],
10492
},

app/src/organisms/Devices/hooks/__tests__/useAttachedPipettes.test.tsx

+9-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
2-
import { when, resetAllWhenMocks } from 'jest-when'
2+
import { vi, it, expect, describe, beforeEach } from 'vitest'
3+
import { when } from 'vitest-when'
34
import { UseQueryResult } from 'react-query'
45
import { renderHook } from '@testing-library/react'
56
import { usePipettesQuery } from '@opentrons/react-api-client'
@@ -12,32 +13,21 @@ import {
1213
import type { FetchPipettesResponseBody } from '@opentrons/api-client'
1314
import type { PipetteModelSpecs } from '@opentrons/shared-data'
1415

15-
jest.mock('@opentrons/react-api-client')
16-
jest.mock('@opentrons/shared-data')
17-
18-
const mockUsePipettesQuery = usePipettesQuery as jest.MockedFunction<
19-
typeof usePipettesQuery
20-
>
21-
const mockGetPipetteModelSpecs = getPipetteModelSpecs as jest.MockedFunction<
22-
typeof getPipetteModelSpecs
23-
>
16+
vi.mock('@opentrons/react-api-client')
17+
vi.mock('@opentrons/shared-data')
2418

2519
describe('useAttachedPipettes hook', () => {
2620
let wrapper: React.FunctionComponent<{ children: React.ReactNode }>
2721
beforeEach(() => {
28-
mockGetPipetteModelSpecs.mockReturnValue({
22+
vi.mocked(getPipetteModelSpecs).mockReturnValue({
2923
name: 'mockName',
3024
} as PipetteModelSpecs)
3125
})
32-
afterEach(() => {
33-
resetAllWhenMocks()
34-
jest.resetAllMocks()
35-
})
3626

3727
it('returns attached pipettes', () => {
38-
when(mockUsePipettesQuery)
28+
when(vi.mocked(usePipettesQuery))
3929
.calledWith({}, {})
40-
.mockReturnValue({
30+
.thenReturn({
4131
data: {
4232
left: pipetteResponseFixtureLeft,
4333
right: pipetteResponseFixtureRight,
@@ -58,9 +48,9 @@ describe('useAttachedPipettes hook', () => {
5848
})
5949

6050
it('returns attached pipettes polled every 5 seconds if poll true', () => {
61-
when(mockUsePipettesQuery)
51+
when(vi.mocked(usePipettesQuery))
6252
.calledWith({}, { refetchInterval: 5000 })
63-
.mockReturnValue({
53+
.thenReturn({
6454
data: {
6555
left: pipetteResponseFixtureLeft,
6656
right: pipetteResponseFixtureRight,

app/src/organisms/Devices/hooks/__tests__/useAttachedPipettesFromInstrumentsQuery.test.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react'
2+
import { vi, it, expect, describe } from 'vitest'
23
import { renderHook } from '@testing-library/react'
34
import { useInstrumentsQuery } from '@opentrons/react-api-client'
45
import {
@@ -7,15 +8,12 @@ import {
78
} from '@opentrons/api-client'
89
import { useAttachedPipettesFromInstrumentsQuery } from '..'
910

10-
jest.mock('@opentrons/react-api-client')
11+
vi.mock('@opentrons/react-api-client')
1112

12-
const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction<
13-
typeof useInstrumentsQuery
14-
>
1513
describe('useAttachedPipettesFromInstrumentsQuery hook', () => {
1614
let wrapper: React.FunctionComponent<{ children: React.ReactNode }>
1715
it('returns attached pipettes', () => {
18-
mockUseInstrumentsQuery.mockReturnValue({
16+
vi.mocked(useInstrumentsQuery).mockReturnValue({
1917
data: {
2018
data: [
2119
instrumentsResponseLeftPipetteFixture,

0 commit comments

Comments
 (0)