1+ import type { KyInstance } from 'ky' ;
12import { HTTPError } from 'ky' ;
23import { describe , expect , it , vi } from 'vitest' ;
34
45import type { ResolvedRequestOptions } from '../bundle' ;
56import { createClient } from '../bundle/client' ;
67
7- type MockKy = ( ( ...args : any [ ] ) => any ) & {
8- preconnect ?: any ;
9- } ;
10-
118describe ( 'buildUrl' , ( ) => {
129 const client = createClient ( ) ;
1310
@@ -87,10 +84,10 @@ describe('zero-length body handling', () => {
8784 status : 200 ,
8885 } ) ;
8986
90- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
87+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
9188
9289 const result = await client . request ( {
93- ky : mockKy ,
90+ ky : mockKy as Partial < KyInstance > as KyInstance ,
9491 method : 'GET' ,
9592 url : '/test' ,
9693 } ) ;
@@ -107,10 +104,10 @@ describe('zero-length body handling', () => {
107104 status : 200 ,
108105 } ) ;
109106
110- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
107+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
111108
112109 const result = await client . request ( {
113- ky : mockKy ,
110+ ky : mockKy as Partial < KyInstance > as KyInstance ,
114111 method : 'GET' ,
115112 parseAs : 'arrayBuffer' ,
116113 url : '/test' ,
@@ -129,10 +126,10 @@ describe('zero-length body handling', () => {
129126 status : 200 ,
130127 } ) ;
131128
132- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
129+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
133130
134131 const result = await client . request ( {
135- ky : mockKy ,
132+ ky : mockKy as Partial < KyInstance > as KyInstance ,
136133 method : 'GET' ,
137134 url : '/test' ,
138135 } ) ;
@@ -149,10 +146,10 @@ describe('zero-length body handling', () => {
149146 status : 200 ,
150147 } ) ;
151148
152- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
149+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
153150
154151 const result = await client . request ( {
155- ky : mockKy ,
152+ ky : mockKy as Partial < KyInstance > as KyInstance ,
156153 method : 'GET' ,
157154 url : '/test' ,
158155 } ) ;
@@ -169,10 +166,10 @@ describe('zero-length body handling', () => {
169166 status : 200 ,
170167 } ) ;
171168
172- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
169+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
173170
174171 const result = await client . request ( {
175- ky : mockKy ,
172+ ky : mockKy as Partial < KyInstance > as KyInstance ,
176173 method : 'GET' ,
177174 url : '/test' ,
178175 } ) ;
@@ -190,10 +187,10 @@ describe('zero-length body handling', () => {
190187 status : 200 ,
191188 } ) ;
192189
193- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
190+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
194191
195192 const result = await client . request ( {
196- ky : mockKy ,
193+ ky : mockKy as Partial < KyInstance > as KyInstance ,
197194 method : 'GET' ,
198195 parseAs : 'stream' ,
199196 url : '/test' ,
@@ -211,10 +208,10 @@ describe('zero-length body handling', () => {
211208 status : 200 ,
212209 } ) ;
213210
214- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
211+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
215212
216213 const result = await client . request ( {
217- ky : mockKy ,
214+ ky : mockKy as Partial < KyInstance > as KyInstance ,
218215 method : 'GET' ,
219216 url : '/test' ,
220217 } ) ;
@@ -244,15 +241,15 @@ describe('unserialized request body handling', () => {
244241 status : 200 ,
245242 } ) ;
246243
247- const mockKy : MockKy = vi . fn ( ) . mockResolvedValueOnce ( mockResponse ) ;
244+ const mockKy = vi . fn ( ) . mockResolvedValueOnce ( mockResponse ) ;
248245
249246 const result = await client . post ( {
250247 body,
251248 bodySerializer : null ,
252249 headers : {
253250 'Content-Type' : 'text/plain' ,
254251 } ,
255- ky : mockKy ,
252+ ky : mockKy as Partial < KyInstance > as KyInstance ,
256253 url : '/test' ,
257254 } ) ;
258255
@@ -319,15 +316,15 @@ describe('serialized request body handling', () => {
319316 status : 200 ,
320317 } ) ;
321318
322- const mockKy : MockKy = vi . fn ( ) . mockResolvedValueOnce ( mockResponse ) ;
319+ const mockKy = vi . fn ( ) . mockResolvedValueOnce ( mockResponse ) ;
323320
324321 const result = await client . post ( {
325322 body,
326323 bodySerializer : ( ) => serializedBody ,
327324 headers : {
328325 'Content-Type' : 'application/json' ,
329326 } ,
330- ky : mockKy ,
327+ ky : mockKy as Partial < KyInstance > as KyInstance ,
331328 url : '/test' ,
332329 } ) ;
333330
@@ -376,7 +373,7 @@ describe('request interceptor', () => {
376373 status : 200 ,
377374 } ) ;
378375
379- const mockKy : MockKy = vi . fn ( ) . mockResolvedValueOnce ( mockResponse ) ;
376+ const mockKy = vi . fn ( ) . mockResolvedValueOnce ( mockResponse ) ;
380377
381378 const mockRequestInterceptor = vi
382379 . fn ( )
@@ -399,7 +396,7 @@ describe('request interceptor', () => {
399396 headers : {
400397 'Content-Type' : contentType ,
401398 } ,
402- ky : mockKy ,
399+ ky : mockKy as Partial < KyInstance > as KyInstance ,
403400 url : '/test' ,
404401 } ) ;
405402
@@ -421,7 +418,7 @@ describe('response interceptor', () => {
421418 status : 200 ,
422419 } ) ;
423420
424- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
421+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
425422
426423 const mockResponseInterceptor = vi
427424 . fn ( )
@@ -435,7 +432,7 @@ describe('response interceptor', () => {
435432 ) ;
436433
437434 await client . get ( {
438- ky : mockKy ,
435+ ky : mockKy as Partial < KyInstance > as KyInstance ,
439436 url : '/test' ,
440437 } ) ;
441438
@@ -459,14 +456,14 @@ describe('error handling', () => {
459456 } ,
460457 ) ;
461458
462- const mockKy : MockKy = vi . fn ( ) . mockRejectedValue (
459+ const mockKy = vi . fn ( ) . mockRejectedValue (
463460 new HTTPError ( errorResponse , new Request ( 'https://example.com/test' ) , {
464461 method : 'GET' ,
465462 } as any ) ,
466463 ) ;
467464
468465 const result = await client . get ( {
469- ky : mockKy ,
466+ ky : mockKy as Partial < KyInstance > as KyInstance ,
470467 throwOnError : false ,
471468 url : '/test' ,
472469 } ) ;
@@ -486,15 +483,15 @@ describe('error handling', () => {
486483 } ,
487484 ) ;
488485
489- const mockKy : MockKy = vi . fn ( ) . mockRejectedValue (
486+ const mockKy = vi . fn ( ) . mockRejectedValue (
490487 new HTTPError ( errorResponse , new Request ( 'https://example.com/test' ) , {
491488 method : 'GET' ,
492489 } as any ) ,
493490 ) ;
494491
495492 await expect (
496493 client . get ( {
497- ky : mockKy ,
494+ ky : mockKy as Partial < KyInstance > as KyInstance ,
498495 throwOnError : true ,
499496 url : '/test' ,
500497 } ) ,
@@ -506,14 +503,14 @@ describe('error handling', () => {
506503 status : 500 ,
507504 } ) ;
508505
509- const mockKy : MockKy = vi . fn ( ) . mockRejectedValue (
506+ const mockKy = vi . fn ( ) . mockRejectedValue (
510507 new HTTPError ( errorResponse , new Request ( 'https://example.com/test' ) , {
511508 method : 'GET' ,
512509 } as any ) ,
513510 ) ;
514511
515512 const result = await client . get ( {
516- ky : mockKy ,
513+ ky : mockKy as Partial < KyInstance > as KyInstance ,
517514 throwOnError : false ,
518515 url : '/test' ,
519516 } ) ;
@@ -537,7 +534,7 @@ describe('error interceptor', () => {
537534 } ,
538535 ) ;
539536
540- const mockKy : MockKy = vi . fn ( ) . mockRejectedValue (
537+ const mockKy = vi . fn ( ) . mockRejectedValue (
541538 new HTTPError ( errorResponse , new Request ( 'https://example.com/test' ) , {
542539 method : 'GET' ,
543540 } as any ) ,
@@ -550,7 +547,7 @@ describe('error interceptor', () => {
550547 const interceptorId = client . interceptors . error . use ( mockErrorInterceptor ) ;
551548
552549 const result = await client . get ( {
553- ky : mockKy ,
550+ ky : mockKy as Partial < KyInstance > as KyInstance ,
554551 throwOnError : false ,
555552 url : '/test' ,
556553 } ) ;
@@ -573,10 +570,10 @@ describe('retry configuration', () => {
573570 status : 200 ,
574571 } ) ;
575572
576- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
573+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
577574
578575 await client . get ( {
579- ky : mockKy ,
576+ ky : mockKy as Partial < KyInstance > as KyInstance ,
580577 retry : {
581578 limit : 3 ,
582579 methods : [ 'get' , 'post' ] ,
@@ -612,10 +609,10 @@ describe('responseStyle configuration', () => {
612609 status : 200 ,
613610 } ) ;
614611
615- const mockKy : MockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
612+ const mockKy = vi . fn ( ) . mockResolvedValue ( mockResponse ) ;
616613
617614 const result = await client . get ( {
618- ky : mockKy ,
615+ ky : mockKy as Partial < KyInstance > as KyInstance ,
619616 url : '/test' ,
620617 } ) ;
621618
@@ -635,14 +632,14 @@ describe('responseStyle configuration', () => {
635632 } ,
636633 ) ;
637634
638- const mockKy : MockKy = vi . fn ( ) . mockRejectedValue (
635+ const mockKy = vi . fn ( ) . mockRejectedValue (
639636 new HTTPError ( errorResponse , new Request ( 'https://example.com/test' ) , {
640637 method : 'GET' ,
641638 } as any ) ,
642639 ) ;
643640
644641 const result = await client . get ( {
645- ky : mockKy ,
642+ ky : mockKy as Partial < KyInstance > as KyInstance ,
646643 throwOnError : false ,
647644 url : '/test' ,
648645 } ) ;
0 commit comments