@@ -134,7 +134,7 @@ describe('::testApiHandler', () => {
134134 } ) ;
135135 } ) ;
136136
137- it ( 'automatically inserts x-msw-bypass when other headers are set through request patcher' , async ( ) => {
137+ it ( 'automatically inserts x-msw-bypass when other headers are set via request patcher' , async ( ) => {
138138 expect . hasAssertions ( ) ;
139139
140140 await testApiHandler ( {
@@ -177,6 +177,34 @@ describe('::testApiHandler', () => {
177177 } ) ;
178178 } ) ;
179179
180+ it ( 'allows unsetting x-msw-bypass via request patcher' , async ( ) => {
181+ expect . hasAssertions ( ) ;
182+
183+ await testApiHandler ( {
184+ requestPatcher : ( req ) => ( req . headers [ 'x-msw-bypass' ] = undefined ) ,
185+ handler : async ( req , res ) => {
186+ res . status ( 200 ) . send ( { mswBypass : req . headers [ 'x-msw-bypass' ] } ) ;
187+ } ,
188+ test : async ( { fetch } ) => {
189+ const res = await fetch ( ) ;
190+ expect ( res . status ) . toBe ( 200 ) ;
191+ await expect ( res . json ( ) ) . resolves . toStrictEqual ( { } ) ;
192+ }
193+ } ) ;
194+
195+ await testApiHandler ( {
196+ requestPatcher : ( req ) => delete req . headers [ 'x-msw-bypass' ] ,
197+ handler : async ( req , res ) => {
198+ res . status ( 200 ) . send ( { mswBypass : req . headers [ 'x-msw-bypass' ] } ) ;
199+ } ,
200+ test : async ( { fetch } ) => {
201+ const res = await fetch ( ) ;
202+ expect ( res . status ) . toBe ( 200 ) ;
203+ await expect ( res . json ( ) ) . resolves . toStrictEqual ( { } ) ;
204+ }
205+ } ) ;
206+ } ) ;
207+
180208 it ( 'respects changes introduced through response patcher' , async ( ) => {
181209 expect . hasAssertions ( ) ;
182210
0 commit comments