File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ export class Ky {
135
135
} ,
136
136
options . hooks ,
137
137
) ,
138
- method : normalizeRequestMethod ( options . method ?? ( this . _input as Request ) . method ) ,
138
+ method : normalizeRequestMethod ( options . method ?? ( this . _input as Request ) . method ?? 'GET' ) ,
139
139
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
140
140
prefixUrl : String ( options . prefixUrl || '' ) ,
141
141
retry : normalizeRetryOptions ( options . retry ) ,
Original file line number Diff line number Diff line change @@ -24,6 +24,29 @@ test('common method is normalized', async t => {
24
24
await server . close ( ) ;
25
25
} ) ;
26
26
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
+
27
50
test . failing ( 'custom method remains identical' , async t => {
28
51
const server = await createHttpTestServer ( ) ;
29
52
server . all ( '/' , ( _request , response ) => {
You can’t perform that action at this time.
0 commit comments