@@ -50,6 +50,11 @@ const duckImage = fs.readFileSync(duckImagePath)
50
50
51
51
describe ( "Wretch" , function ( ) {
52
52
53
+ beforeEach ( ( ) => {
54
+ wretch . defaults ( { } , true )
55
+ wretch . errorType ( "text" )
56
+ } )
57
+
53
58
it ( "should set and use non global polyfills" , async function ( ) {
54
59
global [ "FormData" ] = null
55
60
global [ "URLSearchParams" ] = null
@@ -73,7 +78,7 @@ describe("Wretch", function () {
73
78
performance,
74
79
PerformanceObserver,
75
80
AbortController
76
- } )
81
+ } , true )
77
82
} )
78
83
79
84
it ( "should perform crud requests and parse a text response" , async function ( ) {
@@ -384,7 +389,7 @@ describe("Wretch", function () {
384
389
expect ( check ) . toBe ( 3 )
385
390
} )
386
391
387
- it ( "should set default fetch options" , async function ( ) {
392
+ it ( "should set global default fetch options" , async function ( ) {
388
393
let rejected = await new Promise ( res => wretch ( `${ _URL } /customHeaders` ) . get ( ) . badRequest ( _ => {
389
394
res ( true )
390
395
} ) . res ( result => res ( ! result ) ) )
@@ -458,19 +463,27 @@ describe("Wretch", function () {
458
463
} )
459
464
460
465
it ( "should change the parsing used in the default error handler" , async function ( ) {
466
+ // Local
467
+ await wretch ( `${ _URL } /json500` )
468
+ . errorType ( "json" )
469
+ . get ( )
470
+ . internalError ( error => { expect ( error . json ) . toEqual ( { error : 500 , message : "ok" } ) } )
471
+ . res ( _ => fail ( "I should never be called because an error was thrown" ) )
472
+ . then ( _ => expect ( _ ) . toBe ( undefined ) )
473
+ // Default (text)
461
474
await wretch ( `${ _URL } /json500` )
462
475
. get ( )
463
476
. internalError ( error => { expect ( error . text ) . toEqual ( `{"error":500,"message":"ok"}` ) } )
464
477
. res ( _ => fail ( "I should never be called because an error was thrown" ) )
465
478
. then ( _ => expect ( _ ) . toBe ( undefined ) )
479
+ // Global
466
480
wretch . errorType ( "json" )
467
481
await wretch ( `${ _URL } /json500` )
468
482
. get ( )
469
483
. internalError ( error => { expect ( error . json ) . toEqual ( { error : 500 , message : "ok" } ) } )
470
484
. res ( _ => fail ( "I should never be called because an error was thrown" ) )
471
485
. then ( _ => expect ( _ ) . toBe ( undefined ) )
472
- // Change back
473
- wretch . errorType ( "text" )
486
+
474
487
} )
475
488
476
489
it ( "should retrieve performance timings associated with a fetch request" , function ( done ) {
0 commit comments