test: tighten runtime fetch init assertions · openclaw/openclaw@371563f
shakkernerd
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,6 +40,15 @@ class MockProxyAgent {
|
40 | 40 | readonly __testStub = true; |
41 | 41 | } |
42 | 42 | |
| 43 | +function requireFetchInit(mock: ReturnType<typeof vi.fn>): RequestInit { |
| 44 | +const init = mock.mock.calls[0]?.[1] as RequestInit | undefined; |
| 45 | +expect(init).toBeDefined(); |
| 46 | +if (!init) { |
| 47 | +throw new Error("expected runtime fetch init"); |
| 48 | +} |
| 49 | +return init; |
| 50 | +} |
| 51 | + |
43 | 52 | afterEach(() => { |
44 | 53 | Reflect.deleteProperty(globalThis as object, TEST_UNDICI_RUNTIME_DEPS_KEY); |
45 | 54 | }); |
@@ -74,7 +83,7 @@ describe("fetchWithRuntimeDispatcher", () => {
|
74 | 83 | }); |
75 | 84 | |
76 | 85 | expect(response.status).toBe(200); |
77 | | -const sentHeaders = runtimeFetch.mock.calls[0]?.[1]?.headers; |
| 86 | +const sentHeaders = requireFetchInit(runtimeFetch).headers; |
78 | 87 | expect(sentHeaders).not.toBe(headers); |
79 | 88 | expect(Object.getOwnPropertySymbols(sentHeaders as object)).toEqual([]); |
80 | 89 | expect(Object.getOwnPropertySymbols(headers)).toHaveLength(1); |
@@ -124,7 +133,7 @@ describe("fetchWithRuntimeDispatcher", () => {
|
124 | 133 | |
125 | 134 | expect(response.status).toBe(200); |
126 | 135 | expect(runtimeFetch).toHaveBeenCalledTimes(1); |
127 | | -const sentInit = runtimeFetch.mock.calls[0]?.[1] as RequestInit; |
| 136 | +const sentInit = requireFetchInit(runtimeFetch); |
128 | 137 | const sentHeaders = new Headers(sentInit.headers); |
129 | 138 | expect(sentHeaders.has("content-length")).toBe(false); |
130 | 139 | expect(sentHeaders.has("content-type")).toBe(false); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。