Skip to content

Commit 762ea4c

Browse files
authoredFeb 12, 2025··
Fix options.method being undefined in normalized options (#671)
1 parent 4a42701 commit 762ea4c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎source/core/Ky.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class Ky {
135135
},
136136
options.hooks,
137137
),
138-
method: normalizeRequestMethod(options.method ?? (this._input as Request).method),
138+
method: normalizeRequestMethod(options.method ?? (this._input as Request).method ?? 'GET'),
139139
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
140140
prefixUrl: String(options.prefixUrl || ''),
141141
retry: normalizeRetryOptions(options.retry),

‎test/methods.ts

+23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ test('common method is normalized', async t => {
2424
await server.close();
2525
});
2626

27+
test('method defaults to "GET"', async t => {
28+
const server = await createHttpTestServer();
29+
server.all('/', (_request, response) => {
30+
response.end();
31+
});
32+
33+
t.plan(2);
34+
35+
await t.notThrowsAsync(
36+
ky(server.url, {
37+
hooks: {
38+
beforeRequest: [
39+
(_input, options) => {
40+
t.is(options.method, 'GET');
41+
},
42+
],
43+
},
44+
}),
45+
);
46+
47+
await server.close();
48+
});
49+
2750
test.failing('custom method remains identical', async t => {
2851
const server = await createHttpTestServer();
2952
server.all('/', (_request, response) => {

0 commit comments

Comments
 (0)
Please sign in to comment.