Skip to content

Commit cbf6d5c

Browse files
committed
test: dedupe fetch guard mock reads
1 parent 4fdd71d commit cbf6d5c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎src/infra/net/fetch-guard.ssrf.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function firstMockCall<T extends unknown[]>(mock: { mock: { calls: T[] } }): T |
102102
}
103103

104104
function getSecondRequestHeaders(fetchImpl: ReturnType<typeof vi.fn>): Headers {
105-
const [, secondInit] = fetchImpl.mock.calls.at(1) as [string, RequestInit];
105+
const secondInit = getSecondRequestInit(fetchImpl);
106106
return new Headers(secondInit.headers);
107107
}
108108

@@ -123,7 +123,11 @@ function getFirstRequestInit(fetchImpl: ReturnType<typeof vi.fn>): RequestInit {
123123
}
124124

125125
function getSecondRequestInit(fetchImpl: ReturnType<typeof vi.fn>): RequestInit {
126-
const [, secondInit] = fetchImpl.mock.calls.at(1) as [string, RequestInit];
126+
const call = fetchImpl.mock.calls[1];
127+
if (!call) {
128+
throw new Error("expected second fetch call");
129+
}
130+
const [, secondInit] = call as [string, RequestInit];
127131
return secondInit;
128132
}
129133

0 commit comments

Comments
 (0)