Skip to content

Commit 9f87969

Browse files
committed
refactor: use dot access instead of index key for mock types
1 parent 57ed685 commit 9f87969

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

src/action.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe("Action", () => {
134134
});
135135

136136
it("should handle no distinct_id being provided", () => {
137-
const v4Mock = v4 as unknown as MockInstance<typeof v4>;
137+
const v4Mock = vi.mocked(v4);
138138
v4Mock.mockImplementationOnce(() => "test-uuid-is-used");
139139
mockEnvConfig.distinct_id = "";
140140
const config: ActionConfig = getConfig();

src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type ActionConfig, getConfig } from "./action.ts";
55
import type { Result } from "./types.ts";
66
import { sleep, type BranchNameResult } from "./utils.ts";
77

8-
type Octokit = ReturnType<(typeof github)["getOctokit"]>;
8+
type Octokit = ReturnType<typeof github.getOctokit>;
99

1010
let config: ActionConfig;
1111
let octokit: Octokit;

src/main.spec.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,31 @@ describe("main", () => {
4343
};
4444

4545
// Core
46-
let coreSetFailedMock: MockInstance<(typeof core)["setFailed"]>;
46+
let coreSetFailedMock: MockInstance<typeof core.setFailed>;
4747

4848
// Action
49-
let actionGetConfigMock: MockInstance<(typeof action)["getConfig"]>;
49+
let actionGetConfigMock: MockInstance<typeof action.getConfig>;
5050

5151
// API
52-
let apiDispatchWorkflowMock: MockInstance<(typeof api)["dispatchWorkflow"]>;
53-
let apiInitMock: MockInstance<(typeof api)["init"]>;
52+
let apiDispatchWorkflowMock: MockInstance<typeof api.dispatchWorkflow>;
53+
let apiInitMock: MockInstance<typeof api.init>;
5454

5555
// Utils
56-
let utilsGetBranchNameMock: MockInstance<(typeof utils)["getBranchName"]>;
56+
let utilsGetBranchNameMock: MockInstance<typeof utils.getBranchName>;
5757
let utilsLogInfoForBranchNameResult: MockInstance<
58-
(typeof utils)["logInfoForBranchNameResult"]
58+
typeof utils.logInfoForBranchNameResult
5959
>;
6060

6161
// Return Dispatch
62-
let returnDispatchGetRunIdMock: MockInstance<
63-
(typeof returnDispatch)["getRunId"]
64-
>;
62+
let returnDispatchGetRunIdMock: MockInstance<typeof returnDispatch.getRunId>;
6563
let returnDispatchGetWorkflowIdMock: MockInstance<
66-
(typeof returnDispatch)["getWorkflowId"]
64+
typeof returnDispatch.getWorkflowId
6765
>;
6866
let returnDispatchHandleFailMock: MockInstance<
69-
(typeof returnDispatch)["handleActionFail"]
67+
typeof returnDispatch.handleActionFail
7068
>;
7169
let returnDispatchHandleSuccessMock: MockInstance<
72-
(typeof returnDispatch)["handleActionSuccess"]
70+
typeof returnDispatch.handleActionSuccess
7371
>;
7472

7573
afterAll(() => {

src/return-dispatch.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("return-dispatch", () => {
4545
});
4646

4747
describe("fetchWorkflowId", () => {
48-
let fetchWorkflowIdMock: MockInstance<(typeof api)["fetchWorkflowId"]>;
48+
let fetchWorkflowIdMock: MockInstance<typeof api.fetchWorkflowId>;
4949

5050
beforeAll(() => {
5151
fetchWorkflowIdMock = vi.spyOn(api, "fetchWorkflowId");
@@ -380,8 +380,8 @@ describe("return-dispatch", () => {
380380
});
381381

382382
describe("handleAction", () => {
383-
let setFailedSpy: MockInstance<(typeof core)["setFailed"]>;
384-
let setOutputSpy: MockInstance<(typeof core)["setOutput"]>;
383+
let setFailedSpy: MockInstance<typeof core.setFailed>;
384+
let setOutputSpy: MockInstance<typeof core.setOutput>;
385385

386386
beforeEach(() => {
387387
setFailedSpy = vi.spyOn(core, "setFailed");

src/test-utils/logging.mock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ interface MockedLoggingFunctions {
1616
}
1717

1818
export function mockLoggingFunctions(): MockedLoggingFunctions {
19-
const coreDebugLogMock: MockInstance<(typeof core)["debug"]> = vi
19+
const coreDebugLogMock: MockInstance<typeof core.debug> = vi
2020
.spyOn(core, "debug")
2121
.mockImplementation(() => undefined);
22-
const coreInfoLogMock: MockInstance<(typeof core)["info"]> = vi
22+
const coreInfoLogMock: MockInstance<typeof core.info> = vi
2323
.spyOn(core, "info")
2424
.mockImplementation(() => undefined);
25-
const coreErrorLogMock: MockInstance<(typeof core)["error"]> = vi
25+
const coreErrorLogMock: MockInstance<typeof core.error> = vi
2626
.spyOn(core, "error")
2727
.mockImplementation(() => undefined);
2828

0 commit comments

Comments
 (0)