From 1b23c98d1ead67b00dfe52fcfca0f452444fe02c Mon Sep 17 00:00:00 2001 From: ncdiehl11 Date: Mon, 26 Feb 2024 16:53:58 -0500 Subject: [PATCH] migrate organisms/devices/hooks to vitest --- .../__tests__/useAttachedModules.test.tsx | 10 +- .../useAttachedPipetteCalibrations.test.tsx | 40 +-- .../__tests__/useAttachedPipettes.test.tsx | 28 +- ...tachedPipettesFromInstrumentsQuery.test.ts | 8 +- .../__tests__/useCalibrationTaskList.test.tsx | 314 +++++++++--------- .../__tests__/useDeckCalibrationData.test.tsx | 34 +- .../useDeckCalibrationStatus.test.tsx | 37 +-- .../hooks/__tests__/useIsFlex.test.tsx | 26 +- .../useIsLegacySessionInProgress.test.ts | 12 +- .../hooks/__tests__/useIsRobotBusy.test.ts | 65 ++-- .../__tests__/useIsRobotViewable.test.tsx | 26 +- .../__tests__/useLPCDisabledReason.test.tsx | 80 ++--- .../__tests__/useLPCSuccessToast.test.ts | 19 +- .../hooks/__tests__/useLights.test.tsx | 28 +- .../useModuleCalibrationStatus.test.tsx | 44 ++- ...seModuleRenderInfoForProtocolById.test.tsx | 55 ++- .../usePipetteOffsetCalibration.test.tsx | 41 +-- .../usePipetteOffsetCalibrations.test.tsx | 20 +- .../useProtocolAnalysisErrors.test.tsx | 74 ++--- .../useProtocolDetailsForRun.test.tsx | 49 +-- .../__tests__/useProtocolMetadata.test.tsx | 15 +- .../useProtocolRunAnalyticsData.test.tsx | 66 ++-- .../Devices/hooks/__tests__/useRobot.test.tsx | 20 +- .../__tests__/useRobotAnalyticsData.test.tsx | 50 +-- .../useRunCalibrationStatus.test.tsx | 72 ++-- .../useRunCreatedAtTimestamp.test.tsx | 25 +- .../hooks/__tests__/useRunHasStarted.test.tsx | 22 +- .../useRunPipetteInfoByMount.test.tsx | 88 ++--- ...nStartedOrLegacySessionInProgress.test.tsx | 29 +- .../hooks/__tests__/useRunStatuses.test.tsx | 31 +- .../useStoredProtocolAnalysis.test.tsx | 78 ++--- .../__tests__/useSyncRobotClock.test.tsx | 11 +- .../useTipLengthCalibrations.test.tsx | 14 +- .../useTrackCreateProtocolRunEvent.test.tsx | 53 ++- .../useTrackProtocolRunEvent.test.tsx | 47 ++- .../useUnmatchedModulesForProtocol.test.tsx | 53 ++- shared-data/js/labware.ts | 1 + 37 files changed, 693 insertions(+), 992 deletions(-) diff --git a/app/src/organisms/Devices/hooks/__tests__/useAttachedModules.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useAttachedModules.test.tsx index ec8420edf6b..40886d1f3ed 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useAttachedModules.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useAttachedModules.test.tsx @@ -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' @@ -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({ diff --git a/app/src/organisms/Devices/hooks/__tests__/useAttachedPipetteCalibrations.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useAttachedPipetteCalibrations.test.tsx index d2643cbacba..4681855f02f 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useAttachedPipetteCalibrations.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useAttachedPipetteCalibrations.test.tsx @@ -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' @@ -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 = createStore(jest.fn(), {}) +const store: Store = createStore(state => state, {}) const PIPETTE_CALIBRATIONS = { left: { @@ -61,15 +53,11 @@ describe('useAttachedPipetteCalibrations hook', () => { ) }) - 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, @@ -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], }, diff --git a/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettes.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettes.test.tsx index e94721a957e..1617e15b661 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettes.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettes.test.tsx @@ -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' @@ -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, @@ -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, diff --git a/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettesFromInstrumentsQuery.test.ts b/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettesFromInstrumentsQuery.test.ts index 4d169ce9330..973e4837921 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettesFromInstrumentsQuery.test.ts +++ b/app/src/organisms/Devices/hooks/__tests__/useAttachedPipettesFromInstrumentsQuery.test.ts @@ -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 { @@ -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, diff --git a/app/src/organisms/Devices/hooks/__tests__/useCalibrationTaskList.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useCalibrationTaskList.test.tsx index 60f59f0e2b9..ae48675a201 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useCalibrationTaskList.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useCalibrationTaskList.test.tsx @@ -2,7 +2,8 @@ import * as React from 'react' import { createStore } from 'redux' import { I18nextProvider } from 'react-i18next' import { Provider } from 'react-redux' -import { when, resetAllWhenMocks } from 'jest-when' +import { when } from 'vitest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { renderHook } from '@testing-library/react' import { useDeleteCalibrationMutation, @@ -32,40 +33,24 @@ import { i18n } from '../../../../i18n' import type { Store } from 'redux' import type { State } from '../../../../redux/types' -jest.mock('../') -jest.mock('@opentrons/react-api-client') - -const mockUseAttachedPipettes = useAttachedPipettes as jest.MockedFunction< - typeof useAttachedPipettes -> -const mockUseAllTipLengthCalibrationsQuery = useAllTipLengthCalibrationsQuery as jest.MockedFunction< - typeof useAllTipLengthCalibrationsQuery -> -const mockUseAllPipetteOffsetCalibrationsQuery = useAllPipetteOffsetCalibrationsQuery as jest.MockedFunction< - typeof useAllPipetteOffsetCalibrationsQuery -> -const mockUseCalibrationStatusQuery = useCalibrationStatusQuery as jest.MockedFunction< - typeof useCalibrationStatusQuery -> -const mockUseDeleteCalibrationMutation = useDeleteCalibrationMutation as jest.MockedFunction< - typeof useDeleteCalibrationMutation -> - -const mockPipOffsetCalLauncher = jest.fn() -const mockTipLengthCalLauncher = jest.fn() -const mockDeckCalLauncher = jest.fn() +vi.mock('../') +vi.mock('@opentrons/react-api-client') + +const mockPipOffsetCalLauncher = vi.fn() +const mockTipLengthCalLauncher = vi.fn() +const mockDeckCalLauncher = vi.fn() describe('useCalibrationTaskList hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> let store: Store - const mockDeleteCalibration = jest.fn() + const mockDeleteCalibration = vi.fn() beforeEach(() => { - mockUseDeleteCalibrationMutation.mockReturnValue({ + vi.mocked(useDeleteCalibrationMutation).mockReturnValue({ deleteCalibration: mockDeleteCalibration, } as any) - store = createStore(jest.fn(), {}) - store.dispatch = jest.fn() + store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() wrapper = ({ children }) => ( {children} @@ -73,26 +58,25 @@ describe('useCalibrationTaskList hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns a task list with 3 tasks: Deck Calibration, Left Mount, and Right Mount', () => { const tasks = ['Deck Calibration', 'Left Mount', 'Right Mount'] - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) @@ -115,20 +99,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns a null active index when all calibrations are complete', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) @@ -144,20 +128,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns "Empty" for a mount without an attached pipette', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockSingleAttachedPipetteResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockSingleAttachedPipetteResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -176,20 +160,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active when Deck Calibration is needed', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockIncompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockIncompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -208,20 +192,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active when Deck Recalibration is needed', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockBadDeckCalibration } as any) // markedBad === true - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockBadDeckCalibration } as any) // markedBad === true + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -240,20 +224,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when a pipette is missing Offset Calibrations', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompletePipetteOffsetCalibrations }, } as any) // right mount marked as bad const { result } = renderHook( @@ -272,20 +256,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when both pipettes have bad Offset Calibrations', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockBadPipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -304,20 +288,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when a pipette is missing Tip Length Calibrations', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -336,18 +320,18 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when both pipettes have bad Tip Length Calibrations', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: { data: mockBadTipLengthCalibrations } } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + .thenReturn({ data: { data: mockBadTipLengthCalibrations } } as any) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -366,18 +350,18 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when both tlc and poc are bad', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: { data: mockBadTipLengthCalibrations } } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + .thenReturn({ data: { data: mockBadTipLengthCalibrations } } as any) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockBadPipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -396,20 +380,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when both deck and poc are bad', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockBadDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockBadDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockBadPipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -428,18 +412,18 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the the correct active index when all calibrations are marked bad', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockBadDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockBadDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: { data: mockBadTipLengthCalibrations } } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + .thenReturn({ data: { data: mockBadTipLengthCalibrations } } as any) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockBadPipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -458,20 +442,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns the earliest encountered task as the active index when multiple tasks require calibrations', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockIncompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockIncompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompletePipetteOffsetCalibrations }, } as any) // right mount marked as bad const { result } = renderHook( @@ -490,20 +474,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns descriptions for tasks that need to be completed', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: null } as any) // null deck response - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: null } as any) // null deck response + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompleteTipLengthCalibrations }, } as any) // left calibration missing - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompletePipetteOffsetCalibrations }, } as any) // right mount marked as bad const { result } = renderHook( @@ -530,20 +514,20 @@ describe('useCalibrationTaskList hook', () => { }) it('returns timestamps for tasks that have been completed', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) const { result } = renderHook( @@ -570,20 +554,20 @@ describe('useCalibrationTaskList hook', () => { }) it('passes the launcher function to cta onclick handlers for recalibration', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockCompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockCompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockCompletePipetteOffsetCalibrations }, } as any) @@ -612,20 +596,20 @@ describe('useCalibrationTaskList hook', () => { }) it('passes the launcher function to cta onclick handlers for calibration', () => { - when(mockUseAttachedPipettes) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(mockAttachedPipettesResponse) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockAttachedPipettesResponse) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ data: mockIncompleteDeckCalibration } as any) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn({ data: mockIncompleteDeckCalibration } as any) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompleteTipLengthCalibrations }, } as any) - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: { data: mockIncompletePipetteOffsetCalibrations }, } as any) diff --git a/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationData.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationData.test.tsx index 439e645b316..207eead9d05 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationData.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationData.test.tsx @@ -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, afterEach } from 'vitest' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -20,29 +21,29 @@ import type { DispatchApiRequestType } from '../../../../redux/robot-api' import { useDeckCalibrationData } from '..' import { mockConnectableRobot } from '../../../../redux/discovery/__fixtures__' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../../redux/calibration') -jest.mock('../../../../redux/robot-api') -jest.mock('../../../../redux/discovery') +vi.mock('@opentrons/react-api-client') +vi.mock('../../../../redux/calibration') +vi.mock('../../../../redux/robot-api') +vi.mock('../../../../redux/discovery') -const mockGetDiscoverableRobotByName = getDiscoverableRobotByName as jest.MockedFunction< +const mockGetDiscoverableRobotByName = getDiscoverableRobotByName as vi.mockedFunction< typeof getDiscoverableRobotByName > -const mockUseDispatchApiRequest = useDispatchApiRequest as jest.MockedFunction< +const mockUseDispatchApiRequest = useDispatchApiRequest as vi.mockedFunction< typeof useDispatchApiRequest > -const mockUseCalibrationStatusQuery = useCalibrationStatusQuery as jest.MockedFunction< +const mockUseCalibrationStatusQuery = useCalibrationStatusQuery as vi.mockedFunction< typeof useCalibrationStatusQuery > -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useDeckCalibrationData hook', () => { let dispatchApiRequest: DispatchApiRequestType let wrapper: React.FunctionComponent<{ children: React.ReactNode }> beforeEach(() => { - dispatchApiRequest = jest.fn() + dispatchApiRequest = vi.fn() const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -54,14 +55,13 @@ describe('useDeckCalibrationData hook', () => { mockUseDispatchApiRequest.mockReturnValue([dispatchApiRequest, []]) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns no deck calibration data when given a null robot name', () => { when(mockUseCalibrationStatusQuery) .calledWith({}, null) - .mockReturnValue({ + .thenReturn({ data: { data: { deckCalibration: { @@ -87,11 +87,11 @@ describe('useDeckCalibrationData hook', () => { it('returns deck calibration data when given a robot name', () => { when(mockGetDiscoverableRobotByName) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockConnectableRobot) + .thenReturn(mockConnectableRobot) when(mockUseCalibrationStatusQuery) .calledWith({}, { hostname: mockConnectableRobot.ip }) - .mockReturnValue({ + .thenReturn({ data: { deckCalibration: { data: mockDeckCalData, @@ -114,10 +114,10 @@ describe('useDeckCalibrationData hook', () => { it('returns markedBad deck calibration data when given a failed status', () => { when(mockGetDiscoverableRobotByName) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockConnectableRobot) + .thenReturn(mockConnectableRobot) when(mockUseCalibrationStatusQuery) .calledWith({}, { hostname: mockConnectableRobot.ip }) - .mockReturnValue({ + .thenReturn({ data: { deckCalibration: { data: mockDeckCalData, diff --git a/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationStatus.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationStatus.test.tsx index 6549f430682..25d8dc74ca5 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationStatus.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useDeckCalibrationStatus.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -12,18 +13,11 @@ import { getDiscoverableRobotByName } from '../../../../redux/discovery' import { useDeckCalibrationStatus } from '..' import { mockConnectableRobot } from '../../../../redux/discovery/__fixtures__' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../../redux/calibration') -jest.mock('../../../../redux/discovery') +vi.mock('@opentrons/react-api-client') +vi.mock('../../../../redux/calibration') +vi.mock('../../../../redux/discovery') -const mockGetDiscoverableRobotByName = getDiscoverableRobotByName as jest.MockedFunction< - typeof getDiscoverableRobotByName -> -const mockUseCalibrationStatusQuery = useCalibrationStatusQuery as jest.MockedFunction< - typeof useCalibrationStatusQuery -> - -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useDeckCalibrationStatus hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> @@ -38,17 +32,16 @@ describe('useDeckCalibrationStatus hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns no deck calibration status when no robot provided', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(getDiscoverableRobotByName)) .calledWith(undefined as any, 'null') - .mockReturnValue(null) - when(mockUseCalibrationStatusQuery) + .thenReturn(null) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({}, null) - .mockReturnValue({ data: null } as any) + .thenReturn({ data: null } as any) const { result } = renderHook(() => useDeckCalibrationStatus(null), { wrapper, @@ -58,12 +51,12 @@ describe('useDeckCalibrationStatus hook', () => { }) it('returns deck calibration status when given a robot name', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(getDiscoverableRobotByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockConnectableRobot) - when(mockUseCalibrationStatusQuery) + .thenReturn(mockConnectableRobot) + when(vi.mocked(useCalibrationStatusQuery)) .calledWith({}, { hostname: mockConnectableRobot.ip }) - .mockReturnValue({ + .thenReturn({ data: { deckCalibration: { status: DECK_CAL_STATUS_OK } }, } as any) diff --git a/app/src/organisms/Devices/hooks/__tests__/useIsFlex.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useIsFlex.test.tsx index 776d65b99cb..629f58b7dea 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useIsFlex.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useIsFlex.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -9,13 +10,9 @@ import { getRobotModelByName } from '../../../../redux/discovery' import { useIsFlex } from '..' -jest.mock('../../../../redux/discovery/selectors') +vi.mock('../../../../redux/discovery/selectors') -const mockGetRobotModelByName = getRobotModelByName as jest.MockedFunction< - typeof getRobotModelByName -> - -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useIsFlex hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> @@ -30,14 +27,13 @@ describe('useIsFlex hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns false when given a robot name that does not have a discoverable model', () => { - when(mockGetRobotModelByName) + when(vi.mocked(getRobotModelByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(null) + .thenReturn(null) const { result } = renderHook(() => useIsFlex('otie'), { wrapper }) @@ -45,9 +41,9 @@ describe('useIsFlex hook', () => { }) it('returns true when given a discoverable OT-3 robot name with a model', () => { - when(mockGetRobotModelByName) + when(vi.mocked(getRobotModelByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue('OT-3 Classic') + .thenReturn('OT-3 Classic') const { result } = renderHook(() => useIsFlex('otie'), { wrapper, @@ -56,9 +52,9 @@ describe('useIsFlex hook', () => { expect(result.current).toEqual(true) }) it('returns true when given a discoverable OT-3 robot name with an Opentrons Flex model', () => { - when(mockGetRobotModelByName) + when(vi.mocked(getRobotModelByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue('Opentrons Flex') + .thenReturn('Opentrons Flex') const { result } = renderHook(() => useIsFlex('otie'), { wrapper, diff --git a/app/src/organisms/Devices/hooks/__tests__/useIsLegacySessionInProgress.test.ts b/app/src/organisms/Devices/hooks/__tests__/useIsLegacySessionInProgress.test.ts index 2a101938dd2..115c213dff4 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useIsLegacySessionInProgress.test.ts +++ b/app/src/organisms/Devices/hooks/__tests__/useIsLegacySessionInProgress.test.ts @@ -1,23 +1,21 @@ import { UseQueryResult } from 'react-query' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { useAllSessionsQuery } from '@opentrons/react-api-client' import { useIsLegacySessionInProgress } from '../useIsLegacySessionInProgress' import type { Sessions } from '@opentrons/api-client' -jest.mock('@opentrons/react-api-client') +vi.mock('@opentrons/react-api-client') -const mockUseAllSessionsQuery = useAllSessionsQuery as jest.MockedFunction< - typeof useAllSessionsQuery -> describe('useIsLegacySessionInProgress', () => { beforeEach(() => { - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [], links: null, } as unknown) as UseQueryResult) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns false when sessions are empty', () => { @@ -26,7 +24,7 @@ describe('useIsLegacySessionInProgress', () => { }) it('returns true when sessions are not empty', () => { - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: { data: { id: 'id', diff --git a/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts b/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts index 3057f76d168..2d82b5822f2 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts +++ b/app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts @@ -1,6 +1,7 @@ import { UseQueryResult } from 'react-query' import { useAllSessionsQuery, useEstopQuery } from '@opentrons/react-api-client' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { DISENGAGED, @@ -15,13 +16,11 @@ import { useNotifyAllRunsQuery } from '../../../../resources/runs/useNotifyAllRu import type { Sessions, Runs } from '@opentrons/api-client' import type { AxiosError } from 'axios' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../ProtocolUpload/hooks') -jest.mock('../useIsFlex') -jest.mock('../../../../resources/runs/useNotifyAllRunsQuery') -jest.mock( - '../../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun' -) +vi.mock('@opentrons/react-api-client') +vi.mock('../../../ProtocolUpload/hooks') +vi.mock('../useIsFlex') +vi.mock('../../../../resources/runs/useNotifyAllRunsQuery') +vi.mock('../../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun') const mockEstopStatus = { data: { @@ -31,41 +30,27 @@ const mockEstopStatus = { }, } -const mockUseAllSessionsQuery = useAllSessionsQuery as jest.MockedFunction< - typeof useAllSessionsQuery -> -const mockUseNotifyAllRunsQuery = useNotifyAllRunsQuery as jest.MockedFunction< - typeof useNotifyAllRunsQuery -> -const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jest.MockedFunction< - typeof useNotifyCurrentMaintenanceRun -> -const mockUseEstopQuery = useEstopQuery as jest.MockedFunction< - typeof useEstopQuery -> -const mockUseIsFlex = useIsFlex as jest.MockedFunction - describe('useIsRobotBusy', () => { beforeEach(() => { - mockUseAllSessionsQuery.mockReturnValue({ + vi.mocked(useAllSessionsQuery).mockReturnValue({ data: {}, } as UseQueryResult) - mockUseNotifyAllRunsQuery.mockReturnValue({ + vi.mocked(useNotifyAllRunsQuery).mockReturnValue({ data: { links: { current: {}, }, }, } as UseQueryResult) - mockUseNotifyCurrentMaintenanceRun.mockReturnValue({ + vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({ data: {}, } as any) - mockUseEstopQuery.mockReturnValue({ data: mockEstopStatus } as any) - mockUseIsFlex.mockReturnValue(false) + vi.mocked(useEstopQuery).mockReturnValue({ data: mockEstopStatus } as any) + vi.mocked(useIsFlex).mockReturnValue(false) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns true when current runId is not null', () => { @@ -79,14 +64,14 @@ describe('useIsRobotBusy', () => { }) it('returns false when current runId is null and sessions are empty', () => { - mockUseNotifyAllRunsQuery.mockReturnValue({ + vi.mocked(useNotifyAllRunsQuery).mockReturnValue({ data: { links: { current: null, }, }, } as any) - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [ { id: 'test', @@ -103,14 +88,14 @@ describe('useIsRobotBusy', () => { }) it('returns false when Estop status is disengaged', () => { - mockUseNotifyAllRunsQuery.mockReturnValue({ + vi.mocked(useNotifyAllRunsQuery).mockReturnValue({ data: { links: { current: null, }, }, } as any) - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [ { id: 'test', @@ -127,15 +112,15 @@ describe('useIsRobotBusy', () => { }) it('returns true when robot is a Flex and Estop status is engaged', () => { - mockUseIsFlex.mockReturnValue(true) - mockUseNotifyAllRunsQuery.mockReturnValue({ + vi.mocked(useIsFlex).mockReturnValue(true) + vi.mocked(useNotifyAllRunsQuery).mockReturnValue({ data: { links: { current: null, }, }, } as any) - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [ { id: 'test', @@ -153,20 +138,20 @@ describe('useIsRobotBusy', () => { status: PHYSICALLY_ENGAGED, }, } - mockUseEstopQuery.mockReturnValue({ data: mockEngagedStatus } as any) + vi.mocked(useEstopQuery).mockReturnValue({ data: mockEngagedStatus } as any) const result = useIsRobotBusy() expect(result).toBe(true) }) it('returns false when robot is NOT a Flex and Estop status is engaged', () => { - mockUseIsFlex.mockReturnValue(false) - mockUseNotifyAllRunsQuery.mockReturnValue({ + vi.mocked(useIsFlex).mockReturnValue(false) + vi.mocked(useNotifyAllRunsQuery).mockReturnValue({ data: { links: { current: null, }, }, } as any) - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [ { id: 'test', @@ -184,13 +169,13 @@ describe('useIsRobotBusy', () => { status: PHYSICALLY_ENGAGED, }, } - mockUseEstopQuery.mockReturnValue({ data: mockEngagedStatus } as any) + vi.mocked(useEstopQuery).mockReturnValue({ data: mockEngagedStatus } as any) const result = useIsRobotBusy() expect(result).toBe(false) }) it('returns true when a maintenance run exists', () => { - mockUseNotifyCurrentMaintenanceRun.mockReturnValue({ + vi.mocked(useNotifyCurrentMaintenanceRun).mockReturnValue({ data: { data: { id: '123', diff --git a/app/src/organisms/Devices/hooks/__tests__/useIsRobotViewable.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useIsRobotViewable.test.tsx index df86235c9e7..96ed5c3f92b 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useIsRobotViewable.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useIsRobotViewable.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -14,13 +15,9 @@ import { import { useIsRobotViewable } from '..' -jest.mock('../../../../redux/discovery') +vi.mock('../../../../redux/discovery') -const mockGetDiscoverableRobotByName = getDiscoverableRobotByName as jest.MockedFunction< - typeof getDiscoverableRobotByName -> - -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useIsRobotViewable hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> @@ -35,14 +32,13 @@ describe('useIsRobotViewable hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns false when given an unreachable robot name', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(getDiscoverableRobotByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockUnreachableRobot) + .thenReturn(mockUnreachableRobot) const { result } = renderHook(() => useIsRobotViewable('otie'), { wrapper }) @@ -50,9 +46,9 @@ describe('useIsRobotViewable hook', () => { }) it('returns false when given a reachable robot name', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(getDiscoverableRobotByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockReachableRobot) + .thenReturn(mockReachableRobot) const { result } = renderHook(() => useIsRobotViewable('otie'), { wrapper, @@ -62,9 +58,9 @@ describe('useIsRobotViewable hook', () => { }) it('returns true when given a connectable robot name', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(getDiscoverableRobotByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockConnectableRobot) + .thenReturn(mockConnectableRobot) const { result } = renderHook(() => useIsRobotViewable('otie'), { wrapper, diff --git a/app/src/organisms/Devices/hooks/__tests__/useLPCDisabledReason.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useLPCDisabledReason.test.tsx index bfc2ed3200e..3829c49f78b 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useLPCDisabledReason.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useLPCDisabledReason.test.tsx @@ -3,8 +3,9 @@ import { renderHook } from '@testing-library/react' import { Provider } from 'react-redux' import { I18nextProvider } from 'react-i18next' import { createStore } from 'redux' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { getLoadedLabwareDefinitionsByUri } from '@opentrons/shared-data' -import _uncastedSimpleV6Protocol from '@opentrons/shared-data/protocol/fixtures/6/simpleV6.json' +import { simple_v6 as _uncastedSimpleV6Protocol } from '@opentrons/shared-data' import { i18n } from '../../../../i18n' import { RUN_ID_1 } from '../../../RunTimeControl/__fixtures__' import { useLPCDisabledReason } from '../useLPCDisabledReason' @@ -17,40 +18,23 @@ import { import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis' import type { Store } from 'redux' import type { ProtocolAnalysisOutput } from '@opentrons/shared-data' +import type * as SharedData from '@opentrons/shared-data' import type { State } from '../../../../redux/types' -jest.mock('..') -jest.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') -jest.mock('@opentrons/shared-data', () => { - const actualSharedData = jest.requireActual('@opentrons/shared-data') +vi.mock('..') +vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') +vi.mock('@opentrons/shared-data', async importOriginal => { + const actualSharedData = await importOriginal() return { ...actualSharedData, - getLoadedLabwareDefinitionsByUri: jest.fn(), + getLoadedLabwareDefinitionsByUri: vi.fn(), } }) -const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction< - typeof useMostRecentCompletedAnalysis -> -const mockUseStoredProtocolAnalysis = useStoredProtocolAnalysis as jest.MockedFunction< - typeof useStoredProtocolAnalysis -> -const mockUseRunHasStarted = useRunHasStarted as jest.MockedFunction< - typeof useRunHasStarted -> -const mockUseRunCalibrationStatus = useRunCalibrationStatus as jest.MockedFunction< - typeof useRunCalibrationStatus -> -const mockUseUnmatchedModulesForProtocol = useUnmatchedModulesForProtocol as jest.MockedFunction< - typeof useUnmatchedModulesForProtocol -> -const mockGetLoadedLabwareDefinitionsByUri = getLoadedLabwareDefinitionsByUri as jest.MockedFunction< - typeof getLoadedLabwareDefinitionsByUri -> const simpleV6Protocol = (_uncastedSimpleV6Protocol as unknown) as ProtocolAnalysisOutput describe('useLPCDisabledReason', () => { - const store: Store = createStore(jest.fn(), {}) + const store: Store = createStore(vi.fn(), {}) const wrapper: React.FunctionComponent<{ children: React.ReactNode }> = ({ children, }) => ( @@ -59,23 +43,25 @@ describe('useLPCDisabledReason', () => { ) beforeEach(() => { - store.dispatch = jest.fn() - mockUseMostRecentCompletedAnalysis.mockReturnValue(simpleV6Protocol as any) - mockUseStoredProtocolAnalysis.mockReturnValue( + store.dispatch = vi.fn() + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue( + simpleV6Protocol as any + ) + vi.mocked(useStoredProtocolAnalysis).mockReturnValue( (simpleV6Protocol as unknown) as ProtocolAnalysisOutput ) - mockUseRunHasStarted.mockReturnValue(false) - mockUseRunCalibrationStatus.mockReturnValue({ complete: true }) - mockUseUnmatchedModulesForProtocol.mockReturnValue({ + vi.mocked(useRunHasStarted).mockReturnValue(false) + vi.mocked(useRunCalibrationStatus).mockReturnValue({ complete: true }) + vi.mocked(useUnmatchedModulesForProtocol).mockReturnValue({ missingModuleIds: [], remainingAttachedModules: [], }) - mockGetLoadedLabwareDefinitionsByUri.mockReturnValue( + vi.mocked(getLoadedLabwareDefinitionsByUri).mockReturnValue( _uncastedSimpleV6Protocol.labwareDefinitions as {} ) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('renders no disabled reason', () => { const { result } = renderHook( @@ -111,11 +97,11 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason for module and calibration incomponent', () => { - mockUseUnmatchedModulesForProtocol.mockReturnValue({ + vi.mocked(useUnmatchedModulesForProtocol).mockReturnValue({ missingModuleIds: ['mockId'], remainingAttachedModules: [], }) - mockUseRunCalibrationStatus.mockReturnValue({ complete: false }) + vi.mocked(useRunCalibrationStatus).mockReturnValue({ complete: false }) const { result } = renderHook( () => useLPCDisabledReason({ robotName: 'otie', runId: RUN_ID_1 }), { wrapper } @@ -137,7 +123,7 @@ describe('useLPCDisabledReason', () => { expect(result.current).toStrictEqual('Calibrate pipettes first') }) it('renders disabled reason for calibration incomponent', () => { - mockUseRunCalibrationStatus.mockReturnValue({ complete: false }) + vi.mocked(useRunCalibrationStatus).mockReturnValue({ complete: false }) const { result } = renderHook( () => useLPCDisabledReason({ robotName: 'otie', runId: RUN_ID_1 }), { wrapper } @@ -159,7 +145,7 @@ describe('useLPCDisabledReason', () => { expect(result.current).toStrictEqual('Connect all modules first') }) it('renders disabled reason for missing modules', () => { - mockUseUnmatchedModulesForProtocol.mockReturnValue({ + vi.mocked(useUnmatchedModulesForProtocol).mockReturnValue({ missingModuleIds: ['mockId'], remainingAttachedModules: [], }) @@ -172,7 +158,7 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason for run has started for odd', () => { - mockUseRunHasStarted.mockReturnValue(true) + vi.mocked(useRunHasStarted).mockReturnValue(true) const { result } = renderHook( () => @@ -186,7 +172,7 @@ describe('useLPCDisabledReason', () => { expect(result.current).toStrictEqual('Robot is busy') }) it('renders disabled reason for run has started', () => { - mockUseRunHasStarted.mockReturnValue(true) + vi.mocked(useRunHasStarted).mockReturnValue(true) const { result } = renderHook( () => useLPCDisabledReason({ robotName: 'otie', runId: RUN_ID_1 }), @@ -197,7 +183,7 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason if robot protocol anaylsis is null for odd', () => { - mockUseMostRecentCompletedAnalysis.mockReturnValue(null as any) + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue(null as any) const { result } = renderHook( () => useLPCDisabledReason({ @@ -210,7 +196,7 @@ describe('useLPCDisabledReason', () => { expect(result.current).toStrictEqual('Robot is analyzing') }) it('renders disabled reason if robot protocol anaylsis is null', () => { - mockUseMostRecentCompletedAnalysis.mockReturnValue(null as any) + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue(null as any) const { result } = renderHook( () => useLPCDisabledReason({ robotName: 'otie', runId: RUN_ID_1 }), { wrapper } @@ -220,7 +206,7 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason if no pipettes in protocol for odd', () => { - mockUseMostRecentCompletedAnalysis.mockReturnValue({ + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({ ...simpleV6Protocol, pipettes: {}, } as any) @@ -238,7 +224,7 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason if no pipettes in protocol', () => { - mockUseMostRecentCompletedAnalysis.mockReturnValue({ + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({ ...simpleV6Protocol, pipettes: {}, } as any) @@ -251,7 +237,7 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason if no tipracks in protocols for odd', () => { - mockGetLoadedLabwareDefinitionsByUri.mockReturnValue({}) + vi.mocked(getLoadedLabwareDefinitionsByUri).mockReturnValue({}) const { result } = renderHook( () => @@ -265,7 +251,7 @@ describe('useLPCDisabledReason', () => { expect(result.current).toStrictEqual('Protocol must load a tip rack') }) it('renders disabled reason if no tipracks in protocols', () => { - mockGetLoadedLabwareDefinitionsByUri.mockReturnValue({}) + vi.mocked(getLoadedLabwareDefinitionsByUri).mockReturnValue({}) const { result } = renderHook( () => useLPCDisabledReason({ robotName: 'otie', runId: RUN_ID_1 }), @@ -276,7 +262,7 @@ describe('useLPCDisabledReason', () => { ) }) it('renders disabled reason if no tips are being used in the protocols for odd', () => { - mockUseMostRecentCompletedAnalysis.mockReturnValue({ + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({ ...simpleV6Protocol, commands: {}, } as any) @@ -292,7 +278,7 @@ describe('useLPCDisabledReason', () => { expect(result.current).toStrictEqual('Protocol must pick up a tip') }) it('renders disabled reason if no tips are being used in the protocols', () => { - mockUseMostRecentCompletedAnalysis.mockReturnValue({ + vi.mocked(useMostRecentCompletedAnalysis).mockReturnValue({ ...simpleV6Protocol, commands: {}, } as any) diff --git a/app/src/organisms/Devices/hooks/__tests__/useLPCSuccessToast.test.ts b/app/src/organisms/Devices/hooks/__tests__/useLPCSuccessToast.test.ts index 3877015470b..a64b65252a1 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useLPCSuccessToast.test.ts +++ b/app/src/organisms/Devices/hooks/__tests__/useLPCSuccessToast.test.ts @@ -1,28 +1,31 @@ import * as React from 'react' +import { vi, it, expect, describe } from 'vitest' import { renderHook } from '@testing-library/react' import { useLPCSuccessToast } from '..' +import type * as ReactType from 'react' -jest.mock('react', () => { - const actualReact = jest.requireActual('react') +vi.mock('react', async importOriginal => { + const actualReact = await importOriginal() return { ...actualReact, - useContext: jest.fn(), + useContext: vi.fn(), } }) -const mockUseContext = React.useContext as jest.MockedFunction< - typeof React.useContext -> describe('useLPCSuccessToast', () => { it('return true when useContext returns true', () => { - mockUseContext.mockReturnValue({ setIsShowingLPCSuccessToast: true }) + vi.mocked(React.useContext).mockReturnValue({ + setIsShowingLPCSuccessToast: true, + }) const { result } = renderHook(() => useLPCSuccessToast()) expect(result.current).toStrictEqual({ setIsShowingLPCSuccessToast: true, }) }) it('return false when useContext returns false', () => { - mockUseContext.mockReturnValue({ setIsShowingLPCSuccessToast: false }) + vi.mocked(React.useContext).mockReturnValue({ + setIsShowingLPCSuccessToast: false, + }) const { result } = renderHook(() => useLPCSuccessToast()) expect(result.current).toStrictEqual({ setIsShowingLPCSuccessToast: false, diff --git a/app/src/organisms/Devices/hooks/__tests__/useLights.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useLights.test.tsx index 29c59e6f515..173bfd2375b 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useLights.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useLights.test.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -11,20 +11,13 @@ import { import { useLights } from '..' -jest.mock('@opentrons/react-api-client') +vi.mock('@opentrons/react-api-client') -const mockUseLightsQuery = useLightsQuery as jest.MockedFunction< - typeof useLightsQuery -> -const mockUseSetLightsMutation = useSetLightsMutation as jest.MockedFunction< - typeof useSetLightsMutation -> - -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useLights hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> - let setLights: jest.Mock + let setLights: vi.mock beforeEach(() => { const queryClient = new QueryClient() @@ -35,17 +28,16 @@ describe('useLights hook', () => { ) - mockUseLightsQuery.mockReturnValue({ data: { on: false } } as any) - setLights = jest.fn() - mockUseSetLightsMutation.mockReturnValue({ setLights } as any) + vi.mocked(useLightsQuery).mockReturnValue({ data: { on: false } } as any) + setLights = vi.fn() + vi.mocked(useSetLightsMutation).mockReturnValue({ setLights } as any) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('toggles lights off when on', () => { - mockUseLightsQuery.mockReturnValue({ data: { on: true } } as any) + vi.mocked(useLightsQuery).mockReturnValue({ data: { on: true } } as any) const { result } = renderHook(() => useLights(), { wrapper }) @@ -55,7 +47,7 @@ describe('useLights hook', () => { }) it('toggles lights on when off', () => { - mockUseLightsQuery.mockReturnValue({ data: { on: false } } as any) + vi.mocked(useLightsQuery).mockReturnValue({ data: { on: false } } as any) const { result } = renderHook(() => useLights(), { wrapper, diff --git a/app/src/organisms/Devices/hooks/__tests__/useModuleCalibrationStatus.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useModuleCalibrationStatus.test.tsx index d242d8b69d4..67ae2f37d58 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useModuleCalibrationStatus.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useModuleCalibrationStatus.test.tsx @@ -1,7 +1,8 @@ import * as React from 'react' import { QueryClient, QueryClientProvider } from 'react-query' import { renderHook } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { useIsFlex, @@ -16,13 +17,9 @@ import type { ModuleModel, ModuleType } from '@opentrons/shared-data' import { Provider } from 'react-redux' import { createStore } from 'redux' -jest.mock('../useIsFlex') -jest.mock('../useModuleRenderInfoForProtocolById') +vi.mock('../useIsFlex') +vi.mock('../useModuleRenderInfoForProtocolById') -const mockUseIsFlex = useIsFlex as jest.MockedFunction -const mockUseModuleRenderInfoForProtocolById = useModuleRenderInfoForProtocolById as jest.MockedFunction< - typeof useModuleRenderInfoForProtocolById -> let wrapper: React.FunctionComponent<{ children: React.ReactNode }> const mockMagneticModuleDefinition = { @@ -68,9 +65,9 @@ const mockOffsetData = { describe('useModuleCalibrationStatus hook', () => { beforeEach(() => { const queryClient = new QueryClient() - const store = createStore(jest.fn(), {}) - store.dispatch = jest.fn() - store.getState = jest.fn(() => {}) + const store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() + store.getState = vi.fn(() => {}) wrapper = ({ children }) => ( @@ -79,15 +76,14 @@ describe('useModuleCalibrationStatus hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('should return calibration complete if OT-2', () => { - when(mockUseIsFlex).calledWith('otie').mockReturnValue(false) - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(false) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({}) + .thenReturn({}) const { result } = renderHook( () => useModuleCalibrationStatus('otie', '1'), @@ -98,10 +94,10 @@ describe('useModuleCalibrationStatus hook', () => { }) it('should return calibration complete if no modules needed', () => { - when(mockUseIsFlex).calledWith('otie').mockReturnValue(true) - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(true) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({}) + .thenReturn({}) const { result } = renderHook( () => useModuleCalibrationStatus('otie', '1'), @@ -112,10 +108,10 @@ describe('useModuleCalibrationStatus hook', () => { }) it('should return calibration complete if offset date exists', () => { - when(mockUseIsFlex).calledWith('otie').mockReturnValue(true) - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(true) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ magneticModuleId: { attachedModuleMatch: { ...mockMagneticModuleGen2, @@ -135,10 +131,10 @@ describe('useModuleCalibrationStatus hook', () => { }) it('should return calibration needed if offset date does not exist', () => { - when(mockUseIsFlex).calledWith('otie').mockReturnValue(true) - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(true) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ magneticModuleId: { attachedModuleMatch: { ...mockMagneticModuleGen2, diff --git a/app/src/organisms/Devices/hooks/__tests__/useModuleRenderInfoForProtocolById.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useModuleRenderInfoForProtocolById.test.tsx index 3516c9261ba..73fa81d2075 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useModuleRenderInfoForProtocolById.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useModuleRenderInfoForProtocolById.test.tsx @@ -1,9 +1,10 @@ import { renderHook } from '@testing-library/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 { STAGING_AREA_RIGHT_SLOT_FIXTURE } from '@opentrons/shared-data' -import _heaterShakerCommandsWithResultsKey from '@opentrons/shared-data/protocol/fixtures/6/heaterShakerCommandsWithResultsKey.json' +import { heater_shaker_commands_with_result as _heaterShakerCommandsWithResultsKey } from '@opentrons/shared-data' import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis' import { useDeckConfigurationQuery } from '@opentrons/react-api-client' @@ -28,27 +29,12 @@ import type { ProtocolAnalysisOutput, } from '@opentrons/shared-data' -jest.mock('@opentrons/react-api-client') -jest.mock('../../ProtocolRun/utils/getProtocolModulesInfo') -jest.mock('../useAttachedModules') -jest.mock('../useStoredProtocolAnalysis') -jest.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') +vi.mock('@opentrons/react-api-client') +vi.mock('../../ProtocolRun/utils/getProtocolModulesInfo') +vi.mock('../useAttachedModules') +vi.mock('../useStoredProtocolAnalysis') +vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') -const mockGetProtocolModulesInfo = getProtocolModulesInfo as jest.MockedFunction< - typeof getProtocolModulesInfo -> -const mockUseAttachedModules = useAttachedModules as jest.MockedFunction< - typeof useAttachedModules -> -const mockUseStoredProtocolAnalysis = useStoredProtocolAnalysis as jest.MockedFunction< - typeof useStoredProtocolAnalysis -> -const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction< - typeof useMostRecentCompletedAnalysis -> -const mockUseDeckConfigurationQuery = useDeckConfigurationQuery as jest.MockedFunction< - typeof useDeckConfigurationQuery -> const heaterShakerCommandsWithResultsKey = (_heaterShakerCommandsWithResultsKey as unknown) as ProtocolAnalysisOutput const PROTOCOL_DETAILS = { @@ -132,36 +118,33 @@ const mockCutoutConfig: CutoutConfig = { describe('useModuleRenderInfoForProtocolById hook', () => { beforeEach(() => { - when(mockUseDeckConfigurationQuery).mockReturnValue({ + vi.mocked(useDeckConfigurationQuery).mockReturnValue({ data: [mockCutoutConfig], } as UseQueryResult) - when(mockUseAttachedModules) + when(vi.mocked(useAttachedModules)) .calledWith() - .mockReturnValue([ + .thenReturn([ mockMagneticModuleGen2, mockTemperatureModuleGen2, mockThermocycler, ]) - when(mockUseStoredProtocolAnalysis) + when(vi.mocked(useStoredProtocolAnalysis)) .calledWith('1') - .mockReturnValue((PROTOCOL_DETAILS as unknown) as ProtocolAnalysisOutput) - when(mockUseMostRecentCompletedAnalysis) + .thenReturn((PROTOCOL_DETAILS as unknown) as ProtocolAnalysisOutput) + when(vi.mocked(useMostRecentCompletedAnalysis)) .calledWith('1') - .mockReturnValue(PROTOCOL_DETAILS.protocolData as any) - mockGetProtocolModulesInfo.mockReturnValue([ + .thenReturn(PROTOCOL_DETAILS.protocolData as any) + vi.mocked(getProtocolModulesInfo).mockReturnValue([ TEMPERATURE_MODULE_INFO, MAGNETIC_MODULE_INFO, ]) }) - afterEach(() => { - resetAllWhenMocks() - }) it('should return no module render info when protocol details not found', () => { - when(mockUseMostRecentCompletedAnalysis) + when(vi.mocked(useMostRecentCompletedAnalysis)) .calledWith('1') - .mockReturnValue(null) - when(mockUseStoredProtocolAnalysis).calledWith('1').mockReturnValue(null) + .thenReturn(null) + when(vi.mocked(useStoredProtocolAnalysis)).calledWith('1').thenReturn(null) const { result } = renderHook(() => useModuleRenderInfoForProtocolById('1')) expect(result.current).toStrictEqual({}) }) diff --git a/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibration.test.tsx b/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibration.test.tsx index a30a036529b..6cdf77cdb19 100644 --- a/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibration.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibration.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -18,22 +19,11 @@ import type { DiscoveredRobot } from '../../../../redux/discovery/types' import type { DispatchApiRequestType } from '../../../../redux/robot-api' import { AttachedPipette, Mount } from '../../../../redux/pipettes/types' -jest.mock('../../../../redux/calibration') -jest.mock('../../../../redux/robot-api') -jest.mock('../useRobot') +vi.mock('../../../../redux/calibration') +vi.mock('../../../../redux/robot-api') +vi.mock('../useRobot') -const mockFetchPipetteOffsetCalibrations = fetchPipetteOffsetCalibrations as jest.MockedFunction< - typeof fetchPipetteOffsetCalibrations -> -const mockGetCalibrationForPipette = getCalibrationForPipette as jest.MockedFunction< - typeof getCalibrationForPipette -> -const mockUseDispatchApiRequest = useDispatchApiRequest as jest.MockedFunction< - typeof useDispatchApiRequest -> -const mockUseRobot = useRobot as jest.MockedFunction - -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) const ROBOT_NAME = 'otie' const PIPETTE_ID = 'pipetteId' as AttachedPipette['id'] @@ -43,7 +33,7 @@ describe('usePipetteOffsetCalibration hook', () => { let dispatchApiRequest: DispatchApiRequestType let wrapper: React.FunctionComponent<{ children: React.ReactNode }> beforeEach(() => { - dispatchApiRequest = jest.fn() + dispatchApiRequest = vi.fn() const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -52,18 +42,17 @@ describe('usePipetteOffsetCalibration hook', () => { ) - mockUseDispatchApiRequest.mockReturnValue([dispatchApiRequest, []]) - when(mockUseRobot) + vi.mocked(useDispatchApiRequest).mockReturnValue([dispatchApiRequest, []]) + when(vi.mocked(useRobot)) .calledWith(ROBOT_NAME) - .mockReturnValue(({ status: 'chill' } as unknown) as DiscoveredRobot) + .thenReturn(({ status: 'chill' } as unknown) as DiscoveredRobot) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns no pipette offset calibration when given a null robot name and null pipette id', () => { - mockGetCalibrationForPipette.mockReturnValue(null) + vi.mocked(getCalibrationForPipette).mockReturnValue(null) const { result } = renderHook( () => usePipetteOffsetCalibration(null, null, MOUNT), @@ -77,9 +66,9 @@ describe('usePipetteOffsetCalibration hook', () => { }) it('returns pipette offset calibration when given a robot name, pipette id, and mount', () => { - when(mockGetCalibrationForPipette) + when(vi.mocked(getCalibrationForPipette)) .calledWith(undefined as any, ROBOT_NAME, PIPETTE_ID, MOUNT) - .mockReturnValue(mockPipetteOffsetCalibration1) + .thenReturn(mockPipetteOffsetCalibration1) const { result } = renderHook( () => usePipetteOffsetCalibration(ROBOT_NAME, PIPETTE_ID, MOUNT), @@ -90,7 +79,7 @@ describe('usePipetteOffsetCalibration hook', () => { expect(result.current).toEqual(mockPipetteOffsetCalibration1) expect(dispatchApiRequest).toBeCalledWith( - mockFetchPipetteOffsetCalibrations(ROBOT_NAME) + vi.mocked(fetchPipetteOffsetCalibrations)(ROBOT_NAME) ) }) }) diff --git a/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibrations.test.tsx b/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibrations.test.tsx index 755503279ca..65703fea279 100644 --- a/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibrations.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/usePipetteOffsetCalibrations.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { renderHook } from '@testing-library/react' import { QueryClient, QueryClientProvider } from 'react-query' import { useAllPipetteOffsetCalibrationsQuery } from '@opentrons/react-api-client' @@ -10,11 +11,7 @@ import { } from '../../../../redux/calibration/pipette-offset/__fixtures__' import { usePipetteOffsetCalibrations } from '..' -jest.mock('@opentrons/react-api-client') - -const mockUseAllPipetteOffsetCalibrationsQuery = useAllPipetteOffsetCalibrationsQuery as jest.MockedFunction< - typeof useAllPipetteOffsetCalibrationsQuery -> +vi.mock('@opentrons/react-api-client') const CALIBRATION_DATA_POLL_MS = 5000 @@ -27,14 +24,13 @@ describe('usePipetteOffsetCalibrations hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns empty array when no calibrations found', () => { - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: CALIBRATION_DATA_POLL_MS }) - .mockReturnValue(null as any) + .thenReturn(null as any) const { result } = renderHook(() => usePipetteOffsetCalibrations(), { wrapper, @@ -44,9 +40,9 @@ describe('usePipetteOffsetCalibrations hook', () => { }) it('returns pipette offset calibrations when calibrations found', () => { - when(mockUseAllPipetteOffsetCalibrationsQuery) + when(vi.mocked(useAllPipetteOffsetCalibrationsQuery)) .calledWith({ refetchInterval: CALIBRATION_DATA_POLL_MS }) - .mockReturnValue({ + .thenReturn({ data: { data: [ mockPipetteOffsetCalibration1, diff --git a/app/src/organisms/Devices/hooks/__tests__/useProtocolAnalysisErrors.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useProtocolAnalysisErrors.test.tsx index bcdc00c9624..8fc7cff7d64 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useProtocolAnalysisErrors.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useProtocolAnalysisErrors.test.tsx @@ -1,4 +1,5 @@ -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' @@ -18,43 +19,28 @@ import type { PendingProtocolAnalysis, } from '@opentrons/shared-data' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../../resources/runs/useNotifyRunQuery') - -const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction< - typeof useNotifyRunQuery -> - -const mockUseProtocolQuery = useProtocolQuery as jest.MockedFunction< - typeof useProtocolQuery -> -const mockUseProtocolAnalysisAsDocumentQuery = useProtocolAnalysisAsDocumentQuery as jest.MockedFunction< - typeof useProtocolAnalysisAsDocumentQuery -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../../resources/runs/useNotifyRunQuery') describe('useProtocolAnalysisErrors hook', () => { beforeEach(() => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(null, { staleTime: Infinity }) - .mockReturnValue({} as UseQueryResult) - when(mockUseProtocolQuery) + .thenReturn({} as UseQueryResult) + when(vi.mocked(useProtocolQuery)) .calledWith(null) - .mockReturnValue({} as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + .thenReturn({} as UseQueryResult) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(null, null, { enabled: false }) - .mockReturnValue({ + .thenReturn({ data: null, } as UseQueryResult) }) - afterEach(() => { - resetAllWhenMocks() - }) - it('returns null when protocol id is null', () => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID_2, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: null } } as any, } as UseQueryResult) const { result } = renderHook(() => useProtocolAnalysisErrors(RUN_ID_2)) @@ -69,21 +55,21 @@ describe('useProtocolAnalysisErrors hook', () => { id: 'fake analysis', status: 'completed', } as CompletedProtocolAnalysis - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID_2, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: PROTOCOL_ID } } as any, } as UseQueryResult) - when(mockUseProtocolQuery) + when(vi.mocked(useProtocolQuery)) .calledWith(PROTOCOL_ID) - .mockReturnValue({ + .thenReturn({ data: { data: { analysisSummaries: [{ id: PROTOCOL_ANALYSIS.id }] }, } as any, } as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(PROTOCOL_ID, PROTOCOL_ANALYSIS.id, { enabled: true }) - .mockReturnValue({ + .thenReturn({ data: PROTOCOL_ANALYSIS, } as UseQueryResult) const { result } = renderHook(() => useProtocolAnalysisErrors(RUN_ID_2)) @@ -98,21 +84,21 @@ describe('useProtocolAnalysisErrors hook', () => { id: 'fake analysis', status: 'pending', } as PendingProtocolAnalysis - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID_2, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: PROTOCOL_ID } } as any, } as UseQueryResult) - when(mockUseProtocolQuery) + when(vi.mocked(useProtocolQuery)) .calledWith(PROTOCOL_ID) - .mockReturnValue({ + .thenReturn({ data: { data: { analysisSummaries: [{ id: PROTOCOL_ANALYSIS.id }] }, } as any, } as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(PROTOCOL_ID, PROTOCOL_ANALYSIS.id, { enabled: true }) - .mockReturnValue({ + .thenReturn({ data: PROTOCOL_ANALYSIS, } as UseQueryResult) const { result } = renderHook(() => useProtocolAnalysisErrors(RUN_ID_2)) @@ -128,25 +114,25 @@ describe('useProtocolAnalysisErrors hook', () => { status: 'completed', errors: [{ detail: 'fake error' }], } as CompletedProtocolAnalysis - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID_2, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: PROTOCOL_ID } } as any, } as UseQueryResult) - when(mockUseProtocolQuery) + when(vi.mocked(useProtocolQuery)) .calledWith(PROTOCOL_ID) - .mockReturnValue({ + .thenReturn({ data: { data: { analysisSummaries: [{ id: PROTOCOL_ANALYSIS_WITH_ERRORS.id }], }, } as any, } as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(PROTOCOL_ID, PROTOCOL_ANALYSIS_WITH_ERRORS.id, { enabled: true, }) - .mockReturnValue({ + .thenReturn({ data: PROTOCOL_ANALYSIS_WITH_ERRORS, } as UseQueryResult) const { result } = renderHook(() => useProtocolAnalysisErrors(RUN_ID_2)) diff --git a/app/src/organisms/Devices/hooks/__tests__/useProtocolDetailsForRun.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useProtocolDetailsForRun.test.tsx index 04b0223c3b9..cf57b815dd7 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useProtocolDetailsForRun.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useProtocolDetailsForRun.test.tsx @@ -1,4 +1,5 @@ -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' @@ -18,18 +19,8 @@ import { OT2_ROBOT_TYPE, } from '@opentrons/shared-data' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../../resources/runs/useNotifyRunQuery') - -const mockUseProtocolQuery = useProtocolQuery as jest.MockedFunction< - typeof useProtocolQuery -> -const mockUseProtocolAnalysisAsDocumentQuery = useProtocolAnalysisAsDocumentQuery as jest.MockedFunction< - typeof useProtocolAnalysisAsDocumentQuery -> -const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction< - typeof useNotifyRunQuery -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../../resources/runs/useNotifyRunQuery') const PROTOCOL_ID = 'fake_protocol_id' const PROTOCOL_ANALYSIS = { @@ -51,23 +42,19 @@ const PROTOCOL_RESPONSE = { describe('useProtocolDetailsForRun hook', () => { beforeEach(() => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(null, { staleTime: Infinity }) - .mockReturnValue({} as UseQueryResult) - when(mockUseProtocolQuery) + .thenReturn({} as UseQueryResult) + when(vi.mocked(useProtocolQuery)) .calledWith(null, { staleTime: Infinity }) - .mockReturnValue({} as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + .thenReturn({} as UseQueryResult) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(null, null, { enabled: false, refetchInterval: 5000 }) - .mockReturnValue({ + .thenReturn({ data: null, } as UseQueryResult) }) - afterEach(() => { - resetAllWhenMocks() - }) - it('returns null when given a null run id', async () => { const { result } = renderHook(() => useProtocolDetailsForRun(null)) expect(result.current).toStrictEqual({ @@ -80,28 +67,28 @@ describe('useProtocolDetailsForRun hook', () => { }) it('returns the protocol file when given a run id', async () => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID_2, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: PROTOCOL_ID } } as any, } as UseQueryResult) - when(mockUseProtocolQuery) + when(vi.mocked(useProtocolQuery)) .calledWith(PROTOCOL_ID, { staleTime: Infinity }) - .mockReturnValue({ data: PROTOCOL_RESPONSE } as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + .thenReturn({ data: PROTOCOL_RESPONSE } as UseQueryResult) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(PROTOCOL_ID, 'fake analysis', { enabled: true, refetchInterval: 5000, }) - .mockReturnValue({ + .thenReturn({ data: PROTOCOL_ANALYSIS, } as UseQueryResult) - when(mockUseProtocolAnalysisAsDocumentQuery) + when(vi.mocked(useProtocolAnalysisAsDocumentQuery)) .calledWith(PROTOCOL_ID, 'fake analysis', { enabled: false, refetchInterval: 5000, }) - .mockReturnValue({ + .thenReturn({ data: PROTOCOL_ANALYSIS, } as UseQueryResult) diff --git a/app/src/organisms/Devices/hooks/__tests__/useProtocolMetadata.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useProtocolMetadata.test.tsx index 8ed6189c5d0..c7308201aa6 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useProtocolMetadata.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useProtocolMetadata.test.tsx @@ -1,6 +1,7 @@ // tests for the HostConfig context and hook import * as React from 'react' -import { when } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { Provider } from 'react-redux' import { createStore } from 'redux' import { renderHook } from '@testing-library/react' @@ -10,18 +11,18 @@ import { useProtocolMetadata } from '../useProtocolMetadata' import type { Store } from 'redux' import type { State } from '../../../../redux/types' -jest.mock('../../../ProtocolUpload/hooks') +vi.mock('../../../ProtocolUpload/hooks') -const mockUseCurrentProtocol = useCurrentProtocol as jest.MockedFunction< +const mockUseCurrentProtocol = useCurrentProtocol as vi.mockedFunction< typeof useCurrentProtocol > describe('useProtocolMetadata', () => { - const store: Store = createStore(jest.fn(), {}) + const store: Store = createStore(vi.fn(), {}) when(mockUseCurrentProtocol) .calledWith() - .mockReturnValue({ + .thenReturn({ data: { protocolType: 'json', robotType: 'OT-3 Standard', @@ -34,11 +35,11 @@ describe('useProtocolMetadata', () => { } as any) beforeEach(() => { - store.dispatch = jest.fn() + store.dispatch = vi.fn() }) afterEach(() => { - jest.restoreAllMocks() + vi.restoreAllMocks() }) it('should return author, lastUpdated, method, description, and robot type', () => { diff --git a/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx index 0cfbb7fce93..26bb54173ac 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useProtocolRunAnalyticsData.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { resetAllWhenMocks, when } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { renderHook, waitFor } from '@testing-library/react' import { createStore, Store } from 'redux' import { Provider } from 'react-redux' @@ -13,35 +14,15 @@ import { useProtocolMetadata } from '../useProtocolMetadata' import { useRunTimestamps } from '../../../RunTimeControl/hooks' import { formatInterval } from '../../../RunTimeControl/utils' -jest.mock('../../../../redux/analytics/hash') -jest.mock('../../../../redux/protocol-storage') -jest.mock('../../hooks') -jest.mock('../useProtocolMetadata') -jest.mock('../../../RunTimeControl/hooks') -jest.mock('../../../RunTimeControl/utils') - -const mockHash = hash as jest.MockedFunction -const mockGetStoredProtocol = getStoredProtocol as jest.MockedFunction< - typeof getStoredProtocol -> -const mockUseStoredProtocolAnalysis = useStoredProtocolAnalysis as jest.MockedFunction< - typeof useStoredProtocolAnalysis -> -const mockUseProtocolDetailsForRun = useProtocolDetailsForRun as jest.MockedFunction< - typeof useProtocolDetailsForRun -> -const mockUseProtocolMetadata = useProtocolMetadata as jest.MockedFunction< - typeof useProtocolMetadata -> -const mockUseRunTimestamps = useRunTimestamps as jest.MockedFunction< - typeof useRunTimestamps -> -const mockFormatInterval = formatInterval as jest.MockedFunction< - typeof formatInterval -> +vi.mock('../../../../redux/analytics/hash') +vi.mock('../../../../redux/protocol-storage') +vi.mock('../../hooks') +vi.mock('../useProtocolMetadata') +vi.mock('../../../RunTimeControl/hooks') +vi.mock('../../../RunTimeControl/utils') let wrapper: React.FunctionComponent<{ children: React.ReactNode }> -let store: Store = createStore(jest.fn(), {}) +let store: Store = createStore(vi.fn(), {}) const RUN_ID = '1' const RUN_ID_2 = '2' @@ -76,7 +57,7 @@ const ROBOT_PROTOCOL_ANALYSIS = { describe('useProtocolAnalysisErrors hook', () => { beforeEach(() => { - store = createStore(jest.fn(), {}) + store = createStore(vi.fn(), {}) const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -85,29 +66,30 @@ describe('useProtocolAnalysisErrors hook', () => { ) - mockHash.mockReturnValue(new Promise(resolve => resolve('hashedString'))) - mockGetStoredProtocol.mockReturnValue({ + vi.mocked(hash).mockReturnValue( + new Promise(resolve => resolve('hashedString')) + ) + vi.mocked(getStoredProtocol).mockReturnValue({ srcFiles: Buffer.from('protocol content'), } as any) - when(mockUseStoredProtocolAnalysis) + when(vi.mocked(useStoredProtocolAnalysis)) .calledWith(RUN_ID) - .mockReturnValue(STORED_PROTOCOL_ANALYSIS as any) - when(mockUseProtocolDetailsForRun) + .thenReturn(STORED_PROTOCOL_ANALYSIS as any) + when(vi.mocked(useProtocolDetailsForRun)) .calledWith(RUN_ID) - .mockReturnValue({ protocolData: null } as any) - mockUseProtocolMetadata.mockReturnValue({ + .thenReturn({ protocolData: null } as any) + vi.mocked(useProtocolMetadata).mockReturnValue({ author: 'testAuthor', apiLevel: 2.3, protocolName: 'robot protocol', source: 'robot protocol source', }) - mockUseRunTimestamps.mockReturnValue({ startedAt: '100000' } as any) - mockFormatInterval.mockReturnValue('1:00:00') + vi.mocked(useRunTimestamps).mockReturnValue({ startedAt: '100000' } as any) + vi.mocked(formatInterval).mockReturnValue('1:00:00' as any) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns getProtocolRunAnalyticsData function', () => { @@ -120,9 +102,9 @@ describe('useProtocolAnalysisErrors hook', () => { }) it('getProtocolRunAnalyticsData returns robot data when available', async () => { - when(mockUseProtocolDetailsForRun) + when(vi.mocked(useProtocolDetailsForRun)) .calledWith(RUN_ID_2) - .mockReturnValue({ protocolData: ROBOT_PROTOCOL_ANALYSIS } as any) + .thenReturn({ protocolData: ROBOT_PROTOCOL_ANALYSIS } as any) const { result } = renderHook(() => useProtocolRunAnalyticsData(RUN_ID_2), { wrapper, }) diff --git a/app/src/organisms/Devices/hooks/__tests__/useRobot.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRobot.test.tsx index 5f3320d2ea2..9e074bbd96b 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRobot.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRobot.test.tsx @@ -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, afterEach } from 'vitest' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -10,13 +11,13 @@ import { mockConnectableRobot } from '../../../../redux/discovery/__fixtures__' import { useRobot } from '..' -jest.mock('../../../../redux/discovery') +vi.mock('../../../../redux/discovery') -const mockGetDiscoverableRobotByName = getDiscoverableRobotByName as jest.MockedFunction< +const mockGetDiscoverableRobotByName = getDiscoverableRobotByName as vi.MockedFunction< typeof getDiscoverableRobotByName > -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useRobot hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> @@ -31,14 +32,13 @@ describe('useRobot hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns null when given a robot name that is not discoverable', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(mockGetDiscoverableRobotByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(null) + .thenReturn(null) const { result } = renderHook(() => useRobot('otie'), { wrapper }) @@ -46,9 +46,9 @@ describe('useRobot hook', () => { }) it('returns robot when given a discoverable robot name', () => { - when(mockGetDiscoverableRobotByName) + when(vi.mocked(mockGetDiscoverableRobotByName)) .calledWith(undefined as any, 'otie') - .mockReturnValue(mockConnectableRobot) + .thenReturn(mockConnectableRobot) const { result } = renderHook(() => useRobot('otie'), { wrapper, diff --git a/app/src/organisms/Devices/hooks/__tests__/useRobotAnalyticsData.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRobotAnalyticsData.test.tsx index 9719675a9f4..1b92874c2f5 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRobotAnalyticsData.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRobotAnalyticsData.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { resetAllWhenMocks, when } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { renderHook } from '@testing-library/react' import { createStore, Store } from 'redux' import { Provider } from 'react-redux' @@ -17,25 +18,11 @@ import { import type { DiscoveredRobot } from '../../../../redux/discovery/types' import type { AttachedPipettesByMount } from '../../../../redux/pipettes/types' -jest.mock('@opentrons/react-api-client') -jest.mock('../../hooks') -jest.mock('../../../../redux/discovery') -jest.mock('../../../../redux/pipettes') -jest.mock('../../../../redux/robot-settings') - -const mockUseRobot = useRobot as jest.MockedFunction -const mockGetRobotApiVersion = getRobotApiVersion as jest.MockedFunction< - typeof getRobotApiVersion -> -const mockGetRobotSettings = getRobotSettings as jest.MockedFunction< - typeof getRobotSettings -> -const mockGetRobotFirmwareVersion = getRobotFirmwareVersion as jest.MockedFunction< - typeof getRobotFirmwareVersion -> -const mockGetAttachedPipettes = getAttachedPipettes as jest.MockedFunction< - typeof getAttachedPipettes -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../hooks') +vi.mock('../../../../redux/discovery') +vi.mock('../../../../redux/pipettes') +vi.mock('../../../../redux/robot-settings') const ROBOT_SETTINGS = [ { id: `setting1`, value: true, title: '', description: '' }, @@ -49,12 +36,12 @@ const ATTACHED_PIPETTES = { } let wrapper: React.FunctionComponent<{ children: React.ReactNode }> -let store: Store = createStore(jest.fn(), {}) +let store: Store = createStore(vi.fn(), {}) describe('useProtocolAnalysisErrors hook', () => { beforeEach(() => { - store = createStore(jest.fn(), {}) - store.dispatch = jest.fn() + store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -63,18 +50,17 @@ describe('useProtocolAnalysisErrors hook', () => { ) - when(mockUseRobot).calledWith('noRobot').mockReturnValue(null) - mockGetRobotApiVersion.mockReturnValue(ROBOT_VERSION) - mockGetRobotSettings.mockReturnValue(ROBOT_SETTINGS) - mockGetRobotFirmwareVersion.mockReturnValue(ROBOT_FIRMWARE_VERSION) - mockGetAttachedPipettes.mockReturnValue( + when(vi.mocked(useRobot)).calledWith('noRobot').thenReturn(null) + vi.mocked(getRobotApiVersion).mockReturnValue(ROBOT_VERSION) + vi.mocked(getRobotSettings).mockReturnValue(ROBOT_SETTINGS) + vi.mocked(getRobotFirmwareVersion).mockReturnValue(ROBOT_FIRMWARE_VERSION) + vi.mocked(getAttachedPipettes).mockReturnValue( ATTACHED_PIPETTES as AttachedPipettesByMount ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns null when robot is null or undefined', () => { @@ -85,9 +71,9 @@ describe('useProtocolAnalysisErrors hook', () => { }) it('returns robot analytics data when robot exists', () => { - when(mockUseRobot) + when(vi.mocked(useRobot)) .calledWith('otie') - .mockReturnValue({} as DiscoveredRobot) + .thenReturn({} as DiscoveredRobot) const { result } = renderHook(() => useRobotAnalyticsData('otie'), { wrapper, diff --git a/app/src/organisms/Devices/hooks/__tests__/useRunCalibrationStatus.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRunCalibrationStatus.test.tsx index 421df4215f1..897dbd13394 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRunCalibrationStatus.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRunCalibrationStatus.test.tsx @@ -1,7 +1,8 @@ import * as React from 'react' import { QueryClient, QueryClientProvider } from 'react-query' import { renderHook } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { mockTipRackDefinition } from '../../../../redux/custom-labware/__fixtures__' import { @@ -16,37 +17,29 @@ import type { PipetteInfo } from '..' import { Provider } from 'react-redux' import { createStore } from 'redux' -jest.mock('../useDeckCalibrationStatus') -jest.mock('../useIsFlex') -jest.mock('../useRunPipetteInfoByMount') -jest.mock('../../../../resources/runs/useNotifyRunQuery') +vi.mock('../useDeckCalibrationStatus') +vi.mock('../useIsFlex') +vi.mock('../useRunPipetteInfoByMount') +vi.mock('../../../../resources/runs/useNotifyRunQuery') -const mockUseDeckCalibrationStatus = useDeckCalibrationStatus as jest.MockedFunction< - typeof useDeckCalibrationStatus -> -const mockUseIsFlex = useIsFlex as jest.MockedFunction -const mockUseRunPipetteInfoByMount = useRunPipetteInfoByMount as jest.MockedFunction< - typeof useRunPipetteInfoByMount -> -const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction< - typeof useNotifyRunQuery -> let wrapper: React.FunctionComponent<{ children: React.ReactNode }> describe('useRunCalibrationStatus hook', () => { beforeEach(() => { - when(mockUseDeckCalibrationStatus).calledWith('otie').mockReturnValue('OK') + when(vi.mocked(useDeckCalibrationStatus)) + .calledWith('otie') + .thenReturn('OK') - when(mockUseRunPipetteInfoByMount).calledWith('1').mockReturnValue({ + when(vi.mocked(useRunPipetteInfoByMount)).calledWith('1').thenReturn({ left: null, right: null, }) - when(mockUseIsFlex).calledWith('otie').mockReturnValue(false) - mockUseNotifyRunQuery.mockReturnValue({} as any) + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(false) + vi.mocked(useNotifyRunQuery).mockReturnValue({} as any) - const store = createStore(jest.fn(), {}) - store.dispatch = jest.fn() - store.getState = jest.fn(() => {}) + const store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() + store.getState = vi.fn(() => {}) const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -56,13 +49,10 @@ describe('useRunCalibrationStatus hook', () => { ) }) - afterEach(() => { - resetAllWhenMocks() - }) it('should return deck cal failure if not calibrated', () => { - when(mockUseDeckCalibrationStatus) + when(vi.mocked(useDeckCalibrationStatus)) .calledWith('otie') - .mockReturnValue('BAD_CALIBRATION') + .thenReturn('BAD_CALIBRATION') const { result } = renderHook(() => useRunCalibrationStatus('otie', '1'), { wrapper, }) @@ -72,10 +62,10 @@ describe('useRunCalibrationStatus hook', () => { }) }) it('should ignore deck calibration status of a Flex', () => { - when(mockUseDeckCalibrationStatus) + when(vi.mocked(useDeckCalibrationStatus)) .calledWith('otie') - .mockReturnValue('BAD_CALIBRATION') - when(mockUseIsFlex).calledWith('otie').mockReturnValue(true) + .thenReturn('BAD_CALIBRATION') + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(true) const { result } = renderHook(() => useRunCalibrationStatus('otie', '1'), { wrapper, }) @@ -84,9 +74,9 @@ describe('useRunCalibrationStatus hook', () => { }) }) it('should return attach pipette if missing', () => { - when(mockUseRunPipetteInfoByMount) + when(vi.mocked(useRunPipetteInfoByMount)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ left: { requestedPipetteMatch: 'incompatible', pipetteCalDate: null, @@ -112,9 +102,9 @@ describe('useRunCalibrationStatus hook', () => { }) }) it('should return calibrate pipette if cal date null', () => { - when(mockUseRunPipetteInfoByMount) + when(vi.mocked(useRunPipetteInfoByMount)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ left: { requestedPipetteMatch: 'match', pipetteCalDate: null, @@ -140,9 +130,9 @@ describe('useRunCalibrationStatus hook', () => { }) }) it('should return calibrate tip rack if cal date null', () => { - when(mockUseRunPipetteInfoByMount) + when(vi.mocked(useRunPipetteInfoByMount)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ left: { requestedPipetteMatch: 'match', pipetteCalDate: '2020-08-30T10:02', @@ -168,9 +158,9 @@ describe('useRunCalibrationStatus hook', () => { }) }) it('should ignore tip rack calibration for the Flex', () => { - when(mockUseRunPipetteInfoByMount) + when(vi.mocked(useRunPipetteInfoByMount)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ left: { requestedPipetteMatch: 'match', pipetteCalDate: '2020-08-30T10:02', @@ -187,7 +177,7 @@ describe('useRunCalibrationStatus hook', () => { } as PipetteInfo, right: null, }) - when(mockUseIsFlex).calledWith('otie').mockReturnValue(true) + when(vi.mocked(useIsFlex)).calledWith('otie').thenReturn(true) const { result } = renderHook(() => useRunCalibrationStatus('otie', '1'), { wrapper, }) @@ -196,9 +186,9 @@ describe('useRunCalibrationStatus hook', () => { }) }) it('should return complete if everything is calibrated', () => { - when(mockUseRunPipetteInfoByMount) + when(vi.mocked(useRunPipetteInfoByMount)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ left: { requestedPipetteMatch: 'match', pipetteCalDate: '2020-08-30T10:02', diff --git a/app/src/organisms/Devices/hooks/__tests__/useRunCreatedAtTimestamp.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRunCreatedAtTimestamp.test.tsx index d95579bc7ad..e4399c493db 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRunCreatedAtTimestamp.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRunCreatedAtTimestamp.test.tsx @@ -1,5 +1,6 @@ import { renderHook } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { mockIdleUnstartedRun } from '../../../../organisms/RunTimeControl/__fixtures__' import { formatTimestamp } from '../../utils' @@ -9,31 +10,21 @@ import { useNotifyRunQuery } from '../../../../resources/runs/useNotifyRunQuery' import type { UseQueryResult } from 'react-query' import type { Run } from '@opentrons/api-client' -jest.mock('../../../../resources/runs/useNotifyRunQuery') -jest.mock('../../utils') - -const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction< - typeof useNotifyRunQuery -> -const mockFormatTimestamp = formatTimestamp as jest.MockedFunction< - typeof formatTimestamp -> +vi.mock('../../../../resources/runs/useNotifyRunQuery') +vi.mock('../../utils') const MOCK_RUN_ID = '1' describe('useRunCreatedAtTimestamp', () => { beforeEach(() => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(MOCK_RUN_ID) - .mockReturnValue({ + .thenReturn({ data: { data: mockIdleUnstartedRun }, } as UseQueryResult) - when(mockFormatTimestamp) + when(vi.mocked(formatTimestamp)) .calledWith(mockIdleUnstartedRun.createdAt) - .mockReturnValue('this is formatted') - }) - afterEach(() => { - resetAllWhenMocks() + .thenReturn('this is formatted') }) it('should return a created at timestamp for a run', () => { diff --git a/app/src/organisms/Devices/hooks/__tests__/useRunHasStarted.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRunHasStarted.test.tsx index e5c13169eb8..eb06db5c1e9 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRunHasStarted.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRunHasStarted.test.tsx @@ -1,25 +1,19 @@ import { renderHook } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { RUN_STATUS_IDLE, RUN_STATUS_RUNNING } from '@opentrons/api-client' import { useRunStatus } from '../../../../organisms/RunTimeControl/hooks' import { useRunHasStarted } from '../useRunHasStarted' -jest.mock('../../../../organisms/RunTimeControl/hooks') - -const mockUseRunStatus = useRunStatus as jest.MockedFunction< - typeof useRunStatus -> +vi.mock('../../../../organisms/RunTimeControl/hooks') const MOCK_RUN_ID = '1' describe('useRunHasStarted', () => { beforeEach(() => { - when(mockUseRunStatus).calledWith(null).mockReturnValue(null) - }) - afterEach(() => { - resetAllWhenMocks() + when(vi.mocked(useRunStatus)).calledWith(null).thenReturn(null) }) it('should return false when no run id is provided', () => { @@ -28,17 +22,17 @@ describe('useRunHasStarted', () => { }) it('should return false when run has not started', () => { - when(mockUseRunStatus) + when(vi.mocked(useRunStatus)) .calledWith(MOCK_RUN_ID) - .mockReturnValue(RUN_STATUS_IDLE) + .thenReturn(RUN_STATUS_IDLE) const { result } = renderHook(() => useRunHasStarted(MOCK_RUN_ID)) expect(result.current).toEqual(false) }) it('should return true when run has started', () => { - when(mockUseRunStatus) + when(vi.mocked(useRunStatus)) .calledWith(MOCK_RUN_ID) - .mockReturnValue(RUN_STATUS_RUNNING) + .thenReturn(RUN_STATUS_RUNNING) const { result } = renderHook(() => useRunHasStarted(MOCK_RUN_ID)) expect(result.current).toEqual(true) }) diff --git a/app/src/organisms/Devices/hooks/__tests__/useRunPipetteInfoByMount.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRunPipetteInfoByMount.test.tsx index 6bbe18a90db..61cf8cd5d4d 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRunPipetteInfoByMount.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRunPipetteInfoByMount.test.tsx @@ -1,5 +1,6 @@ import { renderHook } from '@testing-library/react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { getPipetteNameSpecs, @@ -7,7 +8,7 @@ import { RunTimeCommand, } from '@opentrons/shared-data' import { useAllTipLengthCalibrationsQuery } from '@opentrons/react-api-client' -import _tiprack10ul from '@opentrons/shared-data/labware/definitions/2/opentrons_96_tiprack_10ul/1.json' +import { opentrons96Tiprack10UlV1Uncasted as _tiprack10ul } from '@opentrons/shared-data' import { mockPipetteOffsetCalibration1, @@ -35,44 +36,23 @@ import type { PipetteNameSpecs, ProtocolAnalysisOutput, } from '@opentrons/shared-data' +import type * as SharedData from '@opentrons/shared-data' import type { PipetteInfo } from '..' -jest.mock('@opentrons/shared-data', () => { - const actualSharedData = jest.requireActual('@opentrons/shared-data') +vi.mock('@opentrons/shared-data', async importOriginal => { + const actualSharedData = await importOriginal() return { ...actualSharedData, - getPipetteNameSpecs: jest.fn(), - getLoadedLabwareDefinitionsByUri: jest.fn(), + getPipetteNameSpecs: vi.fn(), + getLoadedLabwareDefinitionsByUri: vi.fn(), } }) -jest.mock('@opentrons/react-api-client') -jest.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') -jest.mock('../useAttachedPipetteCalibrations') -jest.mock('../useAttachedPipettes') -jest.mock('../useTipLengthCalibrations') -jest.mock('../useStoredProtocolAnalysis') - -const mockGetPipetteNameSpecs = getPipetteNameSpecs as jest.MockedFunction< - typeof getPipetteNameSpecs -> -const mockUseAttachedPipetteCalibrations = useAttachedPipetteCalibrations as jest.MockedFunction< - typeof useAttachedPipetteCalibrations -> -const mockUseAttachedPipettes = useAttachedPipettes as jest.MockedFunction< - typeof useAttachedPipettes -> -const mockUseAllTipLengthCalibrationsQuery = useAllTipLengthCalibrationsQuery as jest.MockedFunction< - typeof useAllTipLengthCalibrationsQuery -> -const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction< - typeof useMostRecentCompletedAnalysis -> -const mockUseStoredProtocolAnalysis = useStoredProtocolAnalysis as jest.MockedFunction< - typeof useStoredProtocolAnalysis -> -const mockGetLoadedLabwareDefinitionsByUri = getLoadedLabwareDefinitionsByUri as jest.MockedFunction< - typeof getLoadedLabwareDefinitionsByUri -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../LabwarePositionCheck/useMostRecentCompletedAnalysis') +vi.mock('../useAttachedPipetteCalibrations') +vi.mock('../useAttachedPipettes') +vi.mock('../useTipLengthCalibrations') +vi.mock('../useStoredProtocolAnalysis') const PIPETTE_CALIBRATIONS = { left: { @@ -141,44 +121,38 @@ const PROTOCOL_DETAILS = { describe('useRunPipetteInfoByMount hook', () => { beforeEach(() => { - when(mockUseAttachedPipetteCalibrations) + when(vi.mocked(useAttachedPipetteCalibrations)) .calledWith() - .mockReturnValue(PIPETTE_CALIBRATIONS) - when(mockUseAttachedPipettes) + .thenReturn(PIPETTE_CALIBRATIONS) + when(vi.mocked(useAttachedPipettes)) .calledWith() - .mockReturnValue(ATTACHED_PIPETTES) - when(mockUseAllTipLengthCalibrationsQuery) + .thenReturn(ATTACHED_PIPETTES) + when(vi.mocked(useAllTipLengthCalibrationsQuery)) .calledWith() - .mockReturnValue({ data: { data: TIP_LENGTH_CALIBRATIONS } } as any) - when(mockUseMostRecentCompletedAnalysis) + .thenReturn({ data: { data: TIP_LENGTH_CALIBRATIONS } } as any) + when(vi.mocked(useMostRecentCompletedAnalysis)) .calledWith('1') - .mockReturnValue(PROTOCOL_DETAILS.protocolData as any) - when(mockUseStoredProtocolAnalysis) + .thenReturn(PROTOCOL_DETAILS.protocolData as any) + when(vi.mocked(useStoredProtocolAnalysis)) .calledWith('1') - .mockReturnValue((PROTOCOL_DETAILS as unknown) as ProtocolAnalysisOutput) - when(mockGetPipetteNameSpecs) + .thenReturn((PROTOCOL_DETAILS as unknown) as ProtocolAnalysisOutput) + when(vi.mocked(getPipetteNameSpecs)) .calledWith('p10_single') - .mockReturnValue({ + .thenReturn({ displayName: 'P10 Single-Channel GEN1', } as PipetteNameSpecs) - when(mockGetLoadedLabwareDefinitionsByUri) + when(vi.mocked(getLoadedLabwareDefinitionsByUri)) .calledWith( _uncastedModifiedSimpleV6Protocol.commands as RunTimeCommand[] ) - .mockReturnValue( - _uncastedModifiedSimpleV6Protocol.labwareDefinitions as {} - ) - }) - - afterEach(() => { - resetAllWhenMocks() + .thenReturn(_uncastedModifiedSimpleV6Protocol.labwareDefinitions as {}) }) it('should return empty mounts when protocol details not found', () => { - when(mockUseMostRecentCompletedAnalysis) + when(vi.mocked(useMostRecentCompletedAnalysis)) .calledWith('1') - .mockReturnValue(null) - when(mockUseStoredProtocolAnalysis).calledWith('1').mockReturnValue(null) + .thenReturn(null) + when(vi.mocked(useStoredProtocolAnalysis)).calledWith('1').thenReturn(null) const { result } = renderHook(() => useRunPipetteInfoByMount('1')) expect(result.current).toStrictEqual({ left: null, diff --git a/app/src/organisms/Devices/hooks/__tests__/useRunStartedOrLegacySessionInProgress.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRunStartedOrLegacySessionInProgress.test.tsx index 0488727289b..96acc785f07 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRunStartedOrLegacySessionInProgress.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRunStartedOrLegacySessionInProgress.test.tsx @@ -1,6 +1,7 @@ import { UseQueryResult } from 'react-query' import { useAllSessionsQuery } from '@opentrons/react-api-client' import { RUN_STATUS_IDLE, RUN_STATUS_RUNNING } from '@opentrons/api-client' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { useCurrentRunId } from '../../../ProtocolUpload/hooks' import { useRunStatus } from '../../../RunTimeControl/hooks' @@ -8,31 +9,21 @@ import { useRunStartedOrLegacySessionInProgress } from '..' import type { Sessions } from '@opentrons/api-client' -jest.mock('@opentrons/react-api-client') -jest.mock('../../../ProtocolUpload/hooks') -jest.mock('../../../RunTimeControl/hooks') - -const mockUseRunStatus = useRunStatus as jest.MockedFunction< - typeof useRunStatus -> -const mockUseCurrentRunId = useCurrentRunId as jest.MockedFunction< - typeof useCurrentRunId -> -const mockUseAllSessionsQuery = useAllSessionsQuery as jest.MockedFunction< - typeof useAllSessionsQuery -> +vi.mock('@opentrons/react-api-client') +vi.mock('../../../ProtocolUpload/hooks') +vi.mock('../../../RunTimeControl/hooks') describe('useRunStartedOrLegacySessionInProgress', () => { beforeEach(() => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_RUNNING) - mockUseCurrentRunId.mockReturnValue('123') - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_RUNNING) + vi.mocked(useCurrentRunId).mockReturnValue('123') + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [], links: null, } as unknown) as UseQueryResult) }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns true when current run status is not idle or sessions are empty', () => { @@ -41,8 +32,8 @@ describe('useRunStartedOrLegacySessionInProgress', () => { }) it('returns false when run status is idle or sessions are not empty', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_IDLE) - mockUseAllSessionsQuery.mockReturnValue(({ + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_IDLE) + vi.mocked(useAllSessionsQuery).mockReturnValue(({ data: [ { id: 'test', diff --git a/app/src/organisms/Devices/hooks/__tests__/useRunStatuses.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useRunStatuses.test.tsx index 8702713705e..6c805c7ca39 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useRunStatuses.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useRunStatuses.test.tsx @@ -6,31 +6,26 @@ import { RUN_STATUS_STOPPED, RUN_STATUS_SUCCEEDED, } from '@opentrons/api-client' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { useCurrentRunId } from '../../../ProtocolUpload/hooks' import { useRunStatus } from '../../../RunTimeControl/hooks' import { useRunStatuses } from '..' -jest.mock('../../../ProtocolUpload/hooks') -jest.mock('../../../RunTimeControl/hooks') +vi.mock('../../../ProtocolUpload/hooks') +vi.mock('../../../RunTimeControl/hooks') -const mockUseRunStatus = useRunStatus as jest.MockedFunction< - typeof useRunStatus -> -const mockUseCurrentRunId = useCurrentRunId as jest.MockedFunction< - typeof useCurrentRunId -> describe(' useRunStatuses ', () => { beforeEach(() => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_RUNNING) - mockUseCurrentRunId.mockReturnValue('123') + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_RUNNING) + vi.mocked(useCurrentRunId).mockReturnValue('123') }) afterEach(() => { - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns everything as false when run status is null', () => { - mockUseRunStatus.mockReturnValue(null) + vi.mocked(useRunStatus).mockReturnValue(null) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: false, @@ -41,7 +36,7 @@ describe(' useRunStatuses ', () => { }) it('returns true isRunStill and Terminal when run status is suceeded', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_SUCCEEDED) + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_SUCCEEDED) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: false, @@ -52,7 +47,7 @@ describe(' useRunStatuses ', () => { }) it('returns true isRunStill and Terminal when run status is stopped', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_STOPPED) + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_STOPPED) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: false, @@ -63,7 +58,7 @@ describe(' useRunStatuses ', () => { }) it('returns true isRunStill and Terminal when run status is failed', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_FAILED) + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_FAILED) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: false, @@ -74,7 +69,7 @@ describe(' useRunStatuses ', () => { }) it('returns true isRunStill and isRunIdle when run status is idle', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_IDLE) + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_IDLE) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: false, @@ -85,7 +80,7 @@ describe(' useRunStatuses ', () => { }) it('returns true isRunRunning when status is running', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_RUNNING) + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_RUNNING) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: true, @@ -96,7 +91,7 @@ describe(' useRunStatuses ', () => { }) it('returns true isRunRunning when status is paused', () => { - mockUseRunStatus.mockReturnValue(RUN_STATUS_PAUSED) + vi.mocked(useRunStatus).mockReturnValue(RUN_STATUS_PAUSED) const result = useRunStatuses() expect(result).toStrictEqual({ isRunRunning: true, diff --git a/app/src/organisms/Devices/hooks/__tests__/useStoredProtocolAnalysis.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useStoredProtocolAnalysis.test.tsx index f8b152ff4db..62275d66318 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useStoredProtocolAnalysis.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useStoredProtocolAnalysis.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { QueryClient, QueryClientProvider, UseQueryResult } from 'react-query' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' @@ -28,30 +29,12 @@ import { useNotifyRunQuery } from '../../../../resources/runs/useNotifyRunQuery' import type { Protocol, Run } from '@opentrons/api-client' -jest.mock('@opentrons/api-client') -jest.mock('@opentrons/react-api-client') -jest.mock('../../../../redux/protocol-storage/selectors') -jest.mock('../../../../resources/runs/useNotifyRunQuery') - -const mockUseProtocolQuery = useProtocolQuery as jest.MockedFunction< - typeof useProtocolQuery -> -const mockUseNotifyRunQuery = useNotifyRunQuery as jest.MockedFunction< - typeof useNotifyRunQuery -> -const mockGetStoredProtocol = getStoredProtocol as jest.MockedFunction< - typeof getStoredProtocol -> -const mockParseRequiredModulesEntity = parseRequiredModulesEntity as jest.MockedFunction< - typeof parseRequiredModulesEntity -> -const mockParseInitialLoadedLabwareEntity = parseInitialLoadedLabwareEntity as jest.MockedFunction< - typeof parseInitialLoadedLabwareEntity -> -const mockParsePipetteEntity = parsePipetteEntity as jest.MockedFunction< - typeof parsePipetteEntity -> -const store: Store = createStore(jest.fn(), {}) +vi.mock('@opentrons/api-client') +vi.mock('@opentrons/react-api-client') +vi.mock('../../../../redux/protocol-storage/selectors') +vi.mock('../../../../resources/runs/useNotifyRunQuery') + +const store: Store = createStore(vi.fn(), {}) const modifiedStoredProtocolData = { ...storedProtocolData, @@ -78,22 +61,21 @@ describe('useStoredProtocolAnalysis hook', () => { ) - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(null, { staleTime: Infinity }) - .mockReturnValue({} as UseQueryResult) - when(mockUseProtocolQuery) + .thenReturn({} as UseQueryResult) + when(vi.mocked(useProtocolQuery)) .calledWith(null, { staleTime: Infinity }) - .mockReturnValue({} as UseQueryResult) - when(mockGetStoredProtocol) + .thenReturn({} as UseQueryResult) + when(vi.mocked(getStoredProtocol)) .calledWith(undefined as any) - .mockReturnValue(null) - when(mockParseRequiredModulesEntity).mockReturnValue([MODULE_ENTITY]) - when(mockParseInitialLoadedLabwareEntity).mockReturnValue([LABWARE_ENTITY]) - when(mockParsePipetteEntity).mockReturnValue([PIPETTE_ENTITY]) + .thenReturn(null) + vi.mocked(parseRequiredModulesEntity).mockReturnValue([MODULE_ENTITY]) + vi.mocked(parseInitialLoadedLabwareEntity).mockReturnValue([LABWARE_ENTITY]) + vi.mocked(parsePipetteEntity).mockReturnValue([PIPETTE_ENTITY]) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns null when called with null', () => { @@ -105,19 +87,19 @@ describe('useStoredProtocolAnalysis hook', () => { }) it('returns null when there is no stored protocol analysis for a protocol key', () => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: PROTOCOL_ID } }, } as UseQueryResult) - when(mockUseProtocolQuery) + when(vi.mocked(useProtocolQuery)) .calledWith(PROTOCOL_ID, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { key: PROTOCOL_KEY } }, } as UseQueryResult) - when(mockGetStoredProtocol) + when(vi.mocked(getStoredProtocol)) .calledWith(undefined as any, PROTOCOL_KEY) - .mockReturnValue(null) + .thenReturn(null) const { result } = renderHook(() => useStoredProtocolAnalysis(RUN_ID), { wrapper, @@ -127,19 +109,19 @@ describe('useStoredProtocolAnalysis hook', () => { }) it('returns a stored protocol analysis when one exists for a protocol key', () => { - when(mockUseNotifyRunQuery) + when(vi.mocked(useNotifyRunQuery)) .calledWith(RUN_ID, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { protocolId: PROTOCOL_ID } }, } as UseQueryResult) - when(mockUseProtocolQuery) + when(vi.mocked(useProtocolQuery)) .calledWith(PROTOCOL_ID, { staleTime: Infinity }) - .mockReturnValue({ + .thenReturn({ data: { data: { key: PROTOCOL_KEY } }, } as UseQueryResult) - when(mockGetStoredProtocol) + when(vi.mocked(getStoredProtocol)) .calledWith(undefined as any, PROTOCOL_KEY) - .mockReturnValue(modifiedStoredProtocolData as StoredProtocolData) + .thenReturn(modifiedStoredProtocolData as StoredProtocolData) const { result } = renderHook(() => useStoredProtocolAnalysis(RUN_ID), { wrapper, diff --git a/app/src/organisms/Devices/hooks/__tests__/useSyncRobotClock.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useSyncRobotClock.test.tsx index e8ec95a4a78..427535824ee 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useSyncRobotClock.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useSyncRobotClock.test.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { Provider } from 'react-redux' import { createStore, Store } from 'redux' import { renderHook } from '@testing-library/react' @@ -8,14 +8,14 @@ import { QueryClient, QueryClientProvider } from 'react-query' import { syncSystemTime } from '../../../../redux/robot-admin' import { useSyncRobotClock } from '..' -jest.mock('../../../../redux/discovery') +vi.mock('../../../../redux/discovery') -const store: Store = createStore(jest.fn(), {}) +const store: Store = createStore(vi.fn(), {}) describe('useSyncRobotClock hook', () => { let wrapper: React.FunctionComponent<{ children: React.ReactNode }> beforeEach(() => { - store.dispatch = jest.fn() + store.dispatch = vi.fn() const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -26,8 +26,7 @@ describe('useSyncRobotClock hook', () => { ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('dispatches action to sync robot system time on mount and then not again on subsequent renders', () => { diff --git a/app/src/organisms/Devices/hooks/__tests__/useTipLengthCalibrations.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useTipLengthCalibrations.test.tsx index 7934ce0f652..cb06049f818 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useTipLengthCalibrations.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useTipLengthCalibrations.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react' -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { QueryClient, QueryClientProvider } from 'react-query' import { renderHook } from '@testing-library/react' import { useAllTipLengthCalibrationsQuery } from '@opentrons/react-api-client' @@ -10,9 +11,9 @@ import { } from '../../../../redux/calibration/tip-length/__fixtures__' import { useTipLengthCalibrations } from '..' -jest.mock('@opentrons/react-api-client') +vi.mock('@opentrons/react-api-client') -const mockUseAllTipLengthCalibrationsQuery = useAllTipLengthCalibrationsQuery as jest.MockedFunction< +const mockUseAllTipLengthCalibrationsQuery = useAllTipLengthCalibrationsQuery as vi.mockedFunction< typeof useAllTipLengthCalibrationsQuery > @@ -26,8 +27,7 @@ describe('useTipLengthCalibrations hook', () => { {children} ) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) }) @@ -36,7 +36,7 @@ describe('useTipLengthCalibrations hook', () => { .calledWith({ refetchInterval: CALIBRATIONS_FETCH_MS, }) - .mockReturnValue(null as any) + .thenReturn(null as any) const { result } = renderHook(() => useTipLengthCalibrations(), { wrapper, @@ -50,7 +50,7 @@ describe('useTipLengthCalibrations hook', () => { .calledWith({ refetchInterval: CALIBRATIONS_FETCH_MS, }) - .mockReturnValue({ + .thenReturn({ data: { data: [ mockTipLengthCalibration1, diff --git a/app/src/organisms/Devices/hooks/__tests__/useTrackCreateProtocolRunEvent.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useTrackCreateProtocolRunEvent.test.tsx index de223800946..509b779570a 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useTrackCreateProtocolRunEvent.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useTrackCreateProtocolRunEvent.test.tsx @@ -2,7 +2,7 @@ import * as React from 'react' import { createStore, Store } from 'redux' import { Provider } from 'react-redux' import { QueryClient, QueryClientProvider } from 'react-query' -import { resetAllWhenMocks, when } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' import { waitFor, renderHook } from '@testing-library/react' import { STORED_PROTOCOL_ANALYSIS } from '../__fixtures__/storedProtocolAnalysis' @@ -14,35 +14,25 @@ import { storedProtocolData } from '../../../../redux/protocol-storage/__fixture import type { ProtocolAnalyticsData } from '../../../../redux/analytics/types' -jest.mock('../../hooks') -jest.mock('../useProtocolRunAnalyticsData') -jest.mock('../useStoredProtocolAnalysis') -jest.mock('../../../../redux/discovery') -jest.mock('../../../../redux/pipettes') -jest.mock('../../../../redux/analytics') -jest.mock('../../../../redux/robot-settings') - -const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< - typeof useTrackEvent -> -const mockParseProtocolRunAnalyticsData = parseProtocolRunAnalyticsData as jest.MockedFunction< - typeof parseProtocolRunAnalyticsData -> -const mockParseProtocolAnalysisOutput = parseProtocolAnalysisOutput as jest.MockedFunction< - typeof parseProtocolAnalysisOutput -> +vi.mock('../../hooks') +vi.mock('../useProtocolRunAnalyticsData') +vi.mock('../useStoredProtocolAnalysis') +vi.mock('../../../../redux/discovery') +vi.mock('../../../../redux/pipettes') +vi.mock('../../../../redux/analytics') +vi.mock('../../../../redux/robot-settings') const PROTOCOL_PROPERTIES = { protocolType: 'python' } as ProtocolAnalyticsData -let mockTrackEvent: jest.Mock -let mockGetProtocolRunAnalyticsData: jest.Mock +let mockTrackEvent: vi.mock +let mockGetProtocolRunAnalyticsData: vi.mock let wrapper: React.FunctionComponent<{ children: React.ReactNode }> -let store: Store = createStore(jest.fn(), {}) +let store: Store = createStore(vi.fn(), {}) describe('useTrackCreateProtocolRunEvent hook', () => { beforeEach(() => { - store = createStore(jest.fn(), {}) - store.dispatch = jest.fn() + store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -51,23 +41,24 @@ describe('useTrackCreateProtocolRunEvent hook', () => { ) - mockTrackEvent = jest.fn() - mockGetProtocolRunAnalyticsData = jest.fn( + mockTrackEvent = vi.fn() + mockGetProtocolRunAnalyticsData = vi.fn( () => new Promise(resolve => resolve({ protocolRunAnalyticsData: PROTOCOL_PROPERTIES }) ) ) - mockUseTrackEvent.mockReturnValue(mockTrackEvent) - mockParseProtocolAnalysisOutput.mockReturnValue(STORED_PROTOCOL_ANALYSIS) - mockParseProtocolRunAnalyticsData.mockReturnValue( + vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent) + vi.mocked(parseProtocolAnalysisOutput).mockReturnValue( + STORED_PROTOCOL_ANALYSIS + ) + vi.mocked(parseProtocolRunAnalyticsData).mockReturnValue( mockGetProtocolRunAnalyticsData ) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns trackCreateProtocolRunEvent function', () => { @@ -100,7 +91,7 @@ describe('useTrackCreateProtocolRunEvent hook', () => { }) it('trackCreateProtocolRunEvent calls trackEvent with error props when error is thrown in getProtocolRunAnalyticsData', async () => { - when(mockParseProtocolRunAnalyticsData).mockReturnValue( + vi.mocked(parseProtocolRunAnalyticsData).mockReturnValue( () => new Promise(() => { throw new Error('error') diff --git a/app/src/organisms/Devices/hooks/__tests__/useTrackProtocolRunEvent.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useTrackProtocolRunEvent.test.tsx index 5dfff1c91b4..24b0f8e40aa 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useTrackProtocolRunEvent.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useTrackProtocolRunEvent.test.tsx @@ -2,7 +2,8 @@ import * as React from 'react' import { createStore, Store } from 'redux' import { Provider } from 'react-redux' import { QueryClient, QueryClientProvider } from 'react-query' -import { resetAllWhenMocks, when } from 'jest-when' +import { vi, it, expect, describe, beforeEach, afterEach } from 'vitest' +import { when } from 'vitest-when' import { waitFor, renderHook } from '@testing-library/react' import { useTrackProtocolRunEvent } from '../useTrackProtocolRunEvent' @@ -12,32 +13,25 @@ import { ANALYTICS_PROTOCOL_RUN_START, } from '../../../../redux/analytics' -jest.mock('../../hooks') -jest.mock('../useProtocolRunAnalyticsData') -jest.mock('../../../../redux/discovery') -jest.mock('../../../../redux/pipettes') -jest.mock('../../../../redux/analytics') -jest.mock('../../../../redux/robot-settings') - -const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< - typeof useTrackEvent -> -const mockUseProtocolRunAnalyticsData = useProtocolRunAnalyticsData as jest.MockedFunction< - typeof useProtocolRunAnalyticsData -> +vi.mock('../../hooks') +vi.mock('../useProtocolRunAnalyticsData') +vi.mock('../../../../redux/discovery') +vi.mock('../../../../redux/pipettes') +vi.mock('../../../../redux/analytics') +vi.mock('../../../../redux/robot-settings') const RUN_ID = 'runId' const PROTOCOL_PROPERTIES = { protocolType: 'python' } -let mockTrackEvent: jest.Mock -let mockGetProtocolRunAnalyticsData: jest.Mock +let mockTrackEvent: vi.mock +let mockGetProtocolRunAnalyticsData: vi.mock let wrapper: React.FunctionComponent<{ children: React.ReactNode }> -let store: Store = createStore(jest.fn(), {}) +let store: Store = createStore(vi.fn(), {}) describe('useTrackProtocolRunEvent hook', () => { beforeEach(() => { - store = createStore(jest.fn(), {}) - store.dispatch = jest.fn() + store = createStore(vi.fn(), {}) + store.dispatch = vi.fn() const queryClient = new QueryClient() wrapper = ({ children }) => ( @@ -46,22 +40,21 @@ describe('useTrackProtocolRunEvent hook', () => { ) - mockTrackEvent = jest.fn() - mockGetProtocolRunAnalyticsData = jest.fn( + mockTrackEvent = vi.fn() + mockGetProtocolRunAnalyticsData = vi.fn( () => new Promise(resolve => resolve({ protocolRunAnalyticsData: PROTOCOL_PROPERTIES }) ) ) - mockUseTrackEvent.mockReturnValue(mockTrackEvent) - when(mockUseProtocolRunAnalyticsData).calledWith(RUN_ID).mockReturnValue({ + vi.mocked(useTrackEvent).mockReturnValue(mockTrackEvent) + when(vi.mocked(useProtocolRunAnalyticsData)).calledWith(RUN_ID).thenReturn({ getProtocolRunAnalyticsData: mockGetProtocolRunAnalyticsData, }) }) afterEach(() => { - resetAllWhenMocks() - jest.resetAllMocks() + vi.resetAllMocks() }) it('returns trackProtocolRunEvent function', () => { @@ -88,9 +81,9 @@ describe('useTrackProtocolRunEvent hook', () => { }) it('trackProtocolRunEvent calls trackEvent without props when error is thrown in getProtocolRunAnalyticsData', async () => { - when(mockUseProtocolRunAnalyticsData) + when(vi.mocked(useProtocolRunAnalyticsData)) .calledWith('errorId') - .mockReturnValue({ + .thenReturn({ getProtocolRunAnalyticsData: () => new Promise(() => { throw new Error('error') diff --git a/app/src/organisms/Devices/hooks/__tests__/useUnmatchedModulesForProtocol.test.tsx b/app/src/organisms/Devices/hooks/__tests__/useUnmatchedModulesForProtocol.test.tsx index 6fe469954b9..90b666b045a 100644 --- a/app/src/organisms/Devices/hooks/__tests__/useUnmatchedModulesForProtocol.test.tsx +++ b/app/src/organisms/Devices/hooks/__tests__/useUnmatchedModulesForProtocol.test.tsx @@ -1,4 +1,5 @@ -import { when, resetAllWhenMocks } from 'jest-when' +import { vi, it, expect, describe, beforeEach } from 'vitest' +import { when } from 'vitest-when' import { renderHook } from '@testing-library/react' import { mockConnectedRobot } from '../../../../redux/discovery/__fixtures__' @@ -12,17 +13,9 @@ import { import type { ModuleDefinition } from '@opentrons/shared-data' -jest.mock('../useAttachedModules') -jest.mock('../useModuleRenderInfoForProtocolById') -jest.mock('../useRobot') - -const mockUseModuleRenderInfoForProtocolById = useModuleRenderInfoForProtocolById as jest.MockedFunction< - typeof useModuleRenderInfoForProtocolById -> -const mockUseAttachedModules = useAttachedModules as jest.MockedFunction< - typeof useAttachedModules -> -const mockUseRobot = useRobot as jest.MockedFunction +vi.mock('../useAttachedModules') +vi.mock('../useModuleRenderInfoForProtocolById') +vi.mock('../useRobot') const mockMagneticBlockDef = { labwareOffset: { x: 5, y: 5, z: 5 }, @@ -47,28 +40,24 @@ const mockTemperatureModuleDef = { } describe('useModuleMatchResults', () => { beforeEach(() => { - when(mockUseRobot) + when(vi.mocked(useRobot)) .calledWith(mockConnectedRobot.name) - .mockReturnValue(mockConnectedRobot) - when(mockUseModuleRenderInfoForProtocolById) + .thenReturn(mockConnectedRobot) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({}) + .thenReturn({}) - when(mockUseAttachedModules) + when(vi.mocked(useAttachedModules)) .calledWith() - .mockReturnValue([mockTemperatureModule]) - }) - - afterEach(() => { - resetAllWhenMocks() + .thenReturn([mockTemperatureModule]) }) it('should return no missing Module Ids if all connecting modules are present', () => { - when(mockUseAttachedModules).calledWith().mockReturnValue([]) + when(vi.mocked(useAttachedModules)).calledWith().thenReturn([]) const moduleId = 'fakeMagBlockId' - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ [moduleId]: { moduleId: moduleId, x: 0, @@ -94,9 +83,9 @@ describe('useModuleMatchResults', () => { }) it('should return 1 missing moduleId if requested model not attached', () => { const moduleId = 'fakeMagModuleId' - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ [moduleId]: { moduleId: moduleId, x: 0, @@ -112,7 +101,7 @@ describe('useModuleMatchResults', () => { conflictedFixture: null, }, }) - when(mockUseAttachedModules).calledWith().mockReturnValue([]) + when(vi.mocked(useAttachedModules)).calledWith().thenReturn([]) const { result } = renderHook(() => useUnmatchedModulesForProtocol(mockConnectedRobot.name, '1') @@ -122,9 +111,9 @@ describe('useModuleMatchResults', () => { }) it('should return no missing moduleId if compatible model is attached', () => { const moduleId = 'someTempModule' - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ [moduleId]: { moduleId: moduleId, x: 0, @@ -149,9 +138,9 @@ describe('useModuleMatchResults', () => { }) it('should return one missing moduleId if nocompatible model is attached', () => { const moduleId = 'someTempModule' - when(mockUseModuleRenderInfoForProtocolById) + when(vi.mocked(useModuleRenderInfoForProtocolById)) .calledWith('1') - .mockReturnValue({ + .thenReturn({ [moduleId]: { moduleId: moduleId, x: 0, diff --git a/shared-data/js/labware.ts b/shared-data/js/labware.ts index 31a11bd6300..523ffcab3c0 100644 --- a/shared-data/js/labware.ts +++ b/shared-data/js/labware.ts @@ -559,6 +559,7 @@ export { opentrons96PcrAdapterV1, opentrons1Trash3200MlFixedV1, fixtureCalibrationBlock, + opentrons96Tiprack10UlV1Uncasted, } export { getAllLabwareDefs }