Skip to content

Commit

Permalink
migrate organisms/devices/hooks to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ncdiehl11 committed Feb 26, 2024
1 parent e728cf7 commit 1b23c98
Show file tree
Hide file tree
Showing 37 changed files with 693 additions and 992 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resetAllWhenMocks } from 'jest-when'
import { vi, it, expect, describe } from 'vitest'
import { UseQueryResult } from 'react-query'
import { renderHook } from '@testing-library/react'
import { mockModulesResponse } from '@opentrons/api-client'
Expand All @@ -7,18 +7,14 @@ import { useAttachedModules } from '..'

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

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

const mockUseModulesQuery = useModulesQuery as jest.MockedFunction<
const mockUseModulesQuery = useModulesQuery as vi.MockedFunction<
typeof useModulesQuery
>

describe('useAttachedModules hook', () => {
let wrapper: React.FunctionComponent<{ children: React.ReactNode }>
afterEach(() => {
resetAllWhenMocks()
jest.resetAllMocks()
})

it('returns attached modules', () => {
mockUseModulesQuery.mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { when, resetAllWhenMocks } from 'jest-when'
import { when } from 'vitest-when'
import { vi, it, expect, describe, beforeEach } from 'vitest'
import { Provider } from 'react-redux'
import { createStore, Store } from 'redux'
import { renderHook } from '@testing-library/react'
Expand All @@ -20,23 +21,14 @@ import {
} from '../../../../redux/calibration/tip-length/__fixtures__'

import { useAttachedPipetteCalibrations } from '..'
import type { State } from '../../../../redux/types'

jest.mock('@opentrons/react-api-client')
jest.mock('../../../../redux/calibration')
jest.mock('../../../../redux/pipettes')
jest.mock('../../../../redux/robot-api')
vi.mock('@opentrons/react-api-client')
vi.mock('../../../../redux/calibration')
vi.mock('../../../../redux/pipettes')
vi.mock('../../../../redux/robot-api')

const mockUsePipettesQuery = usePipettesQuery as jest.MockedFunction<
typeof usePipettesQuery
>
const mockUseAllPipetteOffsetCalibrationsQuery = useAllPipetteOffsetCalibrationsQuery as jest.MockedFunction<
typeof useAllPipetteOffsetCalibrationsQuery
>
const mockUseAllTipLengthCalibrationsQuery = useAllTipLengthCalibrationsQuery as jest.MockedFunction<
typeof useAllTipLengthCalibrationsQuery
>

const store: Store<any> = createStore(jest.fn(), {})
const store: Store<State> = createStore(state => state, {})

const PIPETTE_CALIBRATIONS = {
left: {
Expand All @@ -61,15 +53,11 @@ describe('useAttachedPipetteCalibrations hook', () => {
</Provider>
)
})
afterEach(() => {
resetAllWhenMocks()
jest.resetAllMocks()
})

it('returns attached pipette calibrations when given a robot name', () => {
when(mockUsePipettesQuery)
when(vi.mocked(usePipettesQuery))
.calledWith({}, {})
.mockReturnValue({
.thenReturn({
data: {
left: {
id: mockPipetteOffsetCalibration1.pipette,
Expand All @@ -89,16 +77,16 @@ describe('useAttachedPipetteCalibrations hook', () => {
},
},
} as any)
when(mockUseAllPipetteOffsetCalibrationsQuery)
when(vi.mocked(useAllPipetteOffsetCalibrationsQuery))
.calledWith()
.mockReturnValue({
.thenReturn({
data: {
data: [mockPipetteOffsetCalibration1, mockPipetteOffsetCalibration2],
},
} as any)
when(mockUseAllTipLengthCalibrationsQuery)
when(vi.mocked(useAllTipLengthCalibrationsQuery))
.calledWith()
.mockReturnValue({
.thenReturn({
data: {
data: [mockTipLengthCalibration1, mockTipLengthCalibration2],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { when, resetAllWhenMocks } from 'jest-when'
import { vi, it, expect, describe, beforeEach } from 'vitest'
import { when } from 'vitest-when'
import { UseQueryResult } from 'react-query'
import { renderHook } from '@testing-library/react'
import { usePipettesQuery } from '@opentrons/react-api-client'
Expand All @@ -12,32 +13,21 @@ import {
import type { FetchPipettesResponseBody } from '@opentrons/api-client'
import type { PipetteModelSpecs } from '@opentrons/shared-data'

jest.mock('@opentrons/react-api-client')
jest.mock('@opentrons/shared-data')

const mockUsePipettesQuery = usePipettesQuery as jest.MockedFunction<
typeof usePipettesQuery
>
const mockGetPipetteModelSpecs = getPipetteModelSpecs as jest.MockedFunction<
typeof getPipetteModelSpecs
>
vi.mock('@opentrons/react-api-client')
vi.mock('@opentrons/shared-data')

describe('useAttachedPipettes hook', () => {
let wrapper: React.FunctionComponent<{ children: React.ReactNode }>
beforeEach(() => {
mockGetPipetteModelSpecs.mockReturnValue({
vi.mocked(getPipetteModelSpecs).mockReturnValue({
name: 'mockName',
} as PipetteModelSpecs)
})
afterEach(() => {
resetAllWhenMocks()
jest.resetAllMocks()
})

it('returns attached pipettes', () => {
when(mockUsePipettesQuery)
when(vi.mocked(usePipettesQuery))
.calledWith({}, {})
.mockReturnValue({
.thenReturn({
data: {
left: pipetteResponseFixtureLeft,
right: pipetteResponseFixtureRight,
Expand All @@ -58,9 +48,9 @@ describe('useAttachedPipettes hook', () => {
})

it('returns attached pipettes polled every 5 seconds if poll true', () => {
when(mockUsePipettesQuery)
when(vi.mocked(usePipettesQuery))
.calledWith({}, { refetchInterval: 5000 })
.mockReturnValue({
.thenReturn({
data: {
left: pipetteResponseFixtureLeft,
right: pipetteResponseFixtureRight,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import { vi, it, expect, describe } from 'vitest'
import { renderHook } from '@testing-library/react'
import { useInstrumentsQuery } from '@opentrons/react-api-client'
import {
Expand All @@ -7,15 +8,12 @@ import {
} from '@opentrons/api-client'
import { useAttachedPipettesFromInstrumentsQuery } from '..'

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

const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction<
typeof useInstrumentsQuery
>
describe('useAttachedPipettesFromInstrumentsQuery hook', () => {
let wrapper: React.FunctionComponent<{ children: React.ReactNode }>
it('returns attached pipettes', () => {
mockUseInstrumentsQuery.mockReturnValue({
vi.mocked(useInstrumentsQuery).mockReturnValue({
data: {
data: [
instrumentsResponseLeftPipetteFixture,
Expand Down
Loading

0 comments on commit 1b23c98

Please sign in to comment.