Skip to content

Commit

Permalink
Merge pull request #1898 from skaut/exact-vitest-types
Browse files Browse the repository at this point in the history
Added types to vi.fn()
  • Loading branch information
marekdedic authored Feb 2, 2025
2 parents 8bab91e + 2a8fc65 commit 430a75d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
18 changes: 9 additions & 9 deletions tests/backend/test-utils/DriveBackedValue-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import type { DriveBackedValue_ } from "../../../src/backend/utils/DriveBackedVa
import type { MoveContext } from "../../../src/interfaces/MoveContext";
import type { MoveError } from "../../../src/interfaces/MoveError";

interface T {
errors: Array<MoveError>;
pathsToProcess: Array<MoveContext>;
}

export function mockedDriveBackedValue(): MockedObject<
DriveBackedValue_<{
errors: Array<MoveError>;
Expand All @@ -12,13 +17,8 @@ export function mockedDriveBackedValue(): MockedObject<
> {
// eslint-disable-next-line vitest/prefer-vi-mocked -- Acceptable as return value
return {
deleteValue: vi.fn(),
loadValue: vi.fn(),
saveValue: vi.fn(),
} as unknown as MockedObject<
DriveBackedValue_<{
errors: Array<MoveError>;
pathsToProcess: Array<MoveContext>;
}>
>;
deleteValue: vi.fn<() => void>(),
loadValue: vi.fn<() => T | null>(),
saveValue: vi.fn<(value: T) => void>(),
} as unknown as MockedObject<DriveBackedValue_<T>>;
}
28 changes: 18 additions & 10 deletions tests/backend/test-utils/MoveState-stub.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { type MockedObject, vi } from "vitest";

import type { MoveState_ } from "../../../src/backend/utils/MoveState";
import type { MoveContext } from "../../../src/interfaces/MoveContext";
import type { MoveError } from "../../../src/interfaces/MoveError";

export function mockedMoveState(): MockedObject<MoveState_> {
// eslint-disable-next-line vitest/prefer-vi-mocked -- Acceptable as return value
return {
addPath: vi.fn(),
destroyState: vi.fn(),
getErrors: vi.fn(),
getNextPath: vi.fn(),
isNull: vi.fn(),
loadState: vi.fn(),
logError: vi.fn(),
removePath: vi.fn(),
saveState: vi.fn(),
tryOrLog: vi.fn(),
addPath:
vi.fn<
(sourceID: string, destinationID: string, path: Array<string>) => void
>(),
destroyState: vi.fn<() => void>(),
getErrors: vi.fn<() => Array<MoveError>>(),
getNextPath: vi.fn<() => MoveContext | null>(),
isNull: vi.fn<() => boolean>(),
loadState: vi.fn<() => void>(),
logError: vi.fn<(file: Array<string>, error: string) => void>(),
removePath: vi.fn<(path: MoveContext) => void>(),
saveState: vi.fn<() => void>(),
tryOrLog: vi.fn<
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generics not supported
(context: MoveContext, fn: () => any, filename?: string) => any
>(),
} as unknown as MockedObject<MoveState_>;
}

0 comments on commit 430a75d

Please sign in to comment.