@@ -15,6 +15,7 @@ test('`url` is required', async t => {
15
15
// @ts -expect-error No argument on purpose.
16
16
got ( ) ,
17
17
{
18
+ instanceOf : RequestError ,
18
19
message : 'Missing `url` property' ,
19
20
} ,
20
21
) ;
@@ -30,6 +31,7 @@ test('`url` should be utf-8 encoded', async t => {
30
31
await t . throwsAsync (
31
32
got ( 'https://example.com/%D2%E0%EB%EB%E8%ED' ) ,
32
33
{
34
+ instanceOf : RequestError ,
33
35
message : 'URI malformed' ,
34
36
} ,
35
37
) ;
@@ -38,12 +40,14 @@ test('`url` should be utf-8 encoded', async t => {
38
40
test ( 'throws if no arguments provided' , async t => {
39
41
// @ts -expect-error Error tests
40
42
await t . throwsAsync ( got ( ) , {
43
+ instanceOf : RequestError ,
41
44
message : 'Missing `url` property' ,
42
45
} ) ;
43
46
} ) ;
44
47
45
48
test ( 'throws if the url option is missing' , async t => {
46
49
await t . throwsAsync ( got ( { } ) , {
50
+ instanceOf : RequestError ,
47
51
message : 'Missing `url` property' ,
48
52
} ) ;
49
53
} ) ;
@@ -93,17 +97,22 @@ test('throws an error when legacy URL is passed', withServer, async (t, server)
93
97
await t . throwsAsync (
94
98
// @ts -expect-error Error tests
95
99
got ( parse ( `${ server . url } /test` ) ) ,
100
+ {
101
+ instanceOf : RequestError ,
102
+ message : 'Expected value which is `predicate returns truthy for any value`, received values of types `Object`.' ,
103
+ } ,
96
104
) ;
97
105
98
- // TODO: Assert message above.
99
-
100
106
await t . throwsAsync (
101
107
got ( {
102
108
protocol : 'http:' ,
103
109
hostname : 'localhost' ,
104
110
port : server . port ,
105
111
} as any ) ,
106
- { message : 'Unexpected option: protocol' } ,
112
+ {
113
+ instanceOf : RequestError ,
114
+ message : 'Unexpected option: protocol' ,
115
+ } ,
107
116
) ;
108
117
} ) ;
109
118
@@ -163,6 +172,7 @@ test('ignores empty searchParams object', withServer, async (t, server, got) =>
163
172
164
173
test ( 'throws when passing body with a non payload method' , async t => {
165
174
await t . throwsAsync ( got ( 'https://example.com' , { body : 'asdf' } ) , {
175
+ instanceOf : RequestError ,
166
176
message : 'The `GET` method cannot be used with a body' ,
167
177
} ) ;
168
178
} ) ;
@@ -206,6 +216,7 @@ test('throws when `options.hooks` is not an object', async t => {
206
216
// @ts -expect-error Error tests
207
217
got ( 'https://example.com' , { hooks : 'not object' } ) ,
208
218
{
219
+ instanceOf : RequestError ,
209
220
message : 'Expected value which is `Object`, received value of type `string`.' ,
210
221
} ,
211
222
) ;
@@ -215,16 +226,19 @@ test('throws when known `options.hooks` value is not an array', async t => {
215
226
await t . throwsAsync (
216
227
// @ts -expect-error Error tests
217
228
got ( 'https://example.com' , { hooks : { beforeRequest : { } } } ) ,
229
+ {
230
+ instanceOf : RequestError ,
231
+ message : 'Expected value which is `predicate returns truthy for any value`, received values of types `Object`.' ,
232
+ } ,
218
233
) ;
219
-
220
- // TODO: Assert message above.
221
234
} ) ;
222
235
223
236
test ( 'throws when known `options.hooks` array item is not a function' , async t => {
224
237
await t . throwsAsync (
225
238
// @ts -expect-error Error tests
226
239
got ( 'https://example.com' , { hooks : { beforeRequest : [ { } ] } } ) ,
227
240
{
241
+ instanceOf : RequestError ,
228
242
message : 'Expected value which is `Function`, received value of type `Object`.' ,
229
243
} ,
230
244
) ;
@@ -235,6 +249,7 @@ test('does not allow extra keys in `options.hooks`', withServer, async (t, serve
235
249
236
250
// @ts -expect-error Error tests
237
251
await t . throwsAsync ( got ( 'test' , { hooks : { extra : [ ] } } ) , {
252
+ instanceOf : RequestError ,
238
253
message : 'Unexpected hook event: extra' ,
239
254
} ) ;
240
255
} ) ;
@@ -286,9 +301,11 @@ test('throws if the `searchParams` value is invalid', async t => {
286
301
// @ts -expect-error Error tests
287
302
foo : [ ] ,
288
303
} ,
289
- } ) ) ;
290
-
291
- // TODO: Assert message above.
304
+ } ) ,
305
+ {
306
+ instanceOf : RequestError ,
307
+ message : 'Expected value which is `predicate returns truthy for any value`, received values of types `Array`.' ,
308
+ } ) ;
292
309
} ) ;
293
310
294
311
test . failing ( '`context` option is enumerable' , withServer , async ( t , server , got ) => {
@@ -365,20 +382,29 @@ test('throws if `options.encoding` is `null`', async t => {
365
382
await t . throwsAsync ( got ( 'https://example.com' , {
366
383
// @ts -expect-error For testing purposes
367
384
encoding : null ,
368
- } ) , { message : 'To get a Buffer, set `options.responseType` to `buffer` instead' } ) ;
385
+ } ) , {
386
+ instanceOf : RequestError ,
387
+ message : 'To get a Buffer, set `options.responseType` to `buffer` instead' ,
388
+ } ) ;
369
389
} ) ;
370
390
371
391
test ( '`url` option and input argument are mutually exclusive' , async t => {
372
392
await t . throwsAsync ( got ( 'https://example.com' , {
373
393
url : 'https://example.com' ,
374
- } ) , { message : 'The `url` option is mutually exclusive with the `input` argument' } ) ;
394
+ } ) , {
395
+ instanceOf : RequestError ,
396
+ message : 'The `url` option is mutually exclusive with the `input` argument' ,
397
+ } ) ;
375
398
} ) ;
376
399
377
400
test ( 'throws a helpful error when passing `followRedirects`' , async t => {
378
401
await t . throwsAsync ( got ( 'https://example.com' , {
379
402
// @ts -expect-error For testing purposes
380
403
followRedirects : true ,
381
- } ) , { message : 'The `followRedirects` option does not exist. Use `followRedirect` instead.' } ) ;
404
+ } ) , {
405
+ instanceOf : RequestError ,
406
+ message : 'The `followRedirects` option does not exist. Use `followRedirect` instead.' ,
407
+ } ) ;
382
408
} ) ;
383
409
384
410
test ( 'merges `searchParams` instances' , t => {
@@ -400,12 +426,14 @@ test('throws a helpful error when passing `auth`', async t => {
400
426
// @ts -expect-error For testing purposes
401
427
auth : 'username:password' ,
402
428
} ) , {
429
+ instanceOf : RequestError ,
403
430
message : 'Parameter `auth` is deprecated. Use `username` / `password` instead.' ,
404
431
} ) ;
405
432
} ) ;
406
433
407
434
test ( 'throws on leading slashes' , async t => {
408
435
await t . throwsAsync ( got ( '/asdf' , { prefixUrl : 'https://example.com' } ) , {
436
+ instanceOf : RequestError ,
409
437
message : '`url` must not start with a slash' ,
410
438
} ) ;
411
439
} ) ;
@@ -414,9 +442,11 @@ test('throws on invalid `dnsCache` option', async t => {
414
442
await t . throwsAsync ( got ( 'https://example.com' , {
415
443
// @ts -expect-error Error tests
416
444
dnsCache : 123 ,
417
- } ) ) ;
418
-
419
- // TODO: Assert message above.
445
+ } ) ,
446
+ {
447
+ instanceOf : RequestError ,
448
+ message : 'Expected value which is `predicate returns truthy for any value`, received values of types `number`.' ,
449
+ } ) ;
420
450
} ) ;
421
451
422
452
test ( 'throws on invalid `agent` option' , async t => {
@@ -425,7 +455,10 @@ test('throws on invalid `agent` option', async t => {
425
455
// @ts -expect-error Error tests
426
456
asdf : 123 ,
427
457
} ,
428
- } ) , { message : 'Unexpected agent option: asdf' } ) ;
458
+ } ) , {
459
+ instanceOf : RequestError ,
460
+ message : 'Unexpected agent option: asdf' ,
461
+ } ) ;
429
462
} ) ;
430
463
431
464
test ( 'fallbacks to native http if `request(...)` returns undefined' , withServer , async ( t , server , got ) => {
@@ -557,6 +590,7 @@ test('throws on too large noise', t => {
557
590
} ,
558
591
} ) ;
559
592
} , {
593
+ instanceOf : Error ,
560
594
message : 'The maximum acceptable retry noise is +/- 100ms, got 101' ,
561
595
} ) ;
562
596
@@ -567,6 +601,7 @@ test('throws on too large noise', t => {
567
601
} ,
568
602
} ) ;
569
603
} , {
604
+ instanceOf : Error ,
570
605
message : 'The maximum acceptable retry noise is +/- 100ms, got -101' ,
571
606
} ) ;
572
607
@@ -577,6 +612,7 @@ test('throws on too large noise', t => {
577
612
} ,
578
613
} ) ;
579
614
} , {
615
+ instanceOf : Error ,
580
616
message : 'The maximum acceptable retry noise is +/- 100ms, got Infinity' ,
581
617
} ) ;
582
618
@@ -587,6 +623,7 @@ test('throws on too large noise', t => {
587
623
} ,
588
624
} ) ;
589
625
} , {
626
+ instanceOf : Error ,
590
627
message : 'The maximum acceptable retry noise is +/- 100ms, got -Infinity' ,
591
628
} ) ;
592
629
@@ -608,6 +645,7 @@ test('options have url even if some are invalid', async t => {
608
645
} ) ) ;
609
646
610
647
t . is ( ( error . options . url as URL ) . href , 'https://example.com/' ) ;
648
+ t . true ( error instanceof Error ) ;
611
649
} ) ;
612
650
613
651
test ( 'options have url even if some are invalid - got.extend' , async t => {
@@ -623,5 +661,8 @@ test('options have url even if some are invalid - got.extend', async t => {
623
661
await t . throwsAsync ( instance ( 'https://example.com' , {
624
662
// @ts -expect-error Testing purposes
625
663
invalid : true ,
626
- } ) ) ;
664
+ } ) ,
665
+ {
666
+ instanceOf : Error ,
667
+ } ) ;
627
668
} ) ;
0 commit comments