1- /**
2- * @vitest -environment node
3- */
1+ // @vitest -environment node
42import { HttpResponse , http } from 'msw'
53import { setupServer } from 'msw/node'
64import { encodeBuffer } from '@mswjs/interceptors'
@@ -20,61 +18,56 @@ afterAll(() => {
2018} )
2119
2220test ( 'reads plain text request body as text' , async ( ) => {
23- const res = await fetch ( 'http://localhost/resource' , {
21+ const response = await fetch ( 'http://localhost/resource' , {
2422 method : 'POST' ,
2523 headers : {
2624 'Content-Type' : 'text/plain' ,
2725 } ,
2826 body : 'hello-world' ,
2927 } )
30- const body = await res . text ( )
3128
32- expect ( res . status ) . toBe ( 200 )
33- expect ( body ) . toBe ( 'hello-world' )
29+ expect . soft ( response . status ) . toBe ( 200 )
30+ await expect . soft ( response . text ( ) ) . resolves . toBe ( 'hello-world' )
3431} )
3532
3633test ( 'reads json request body as text' , async ( ) => {
37- const res = await fetch ( 'http://localhost/resource' , {
34+ const response = await fetch ( 'http://localhost/resource' , {
3835 method : 'POST' ,
3936 headers : {
4037 'Content-Type' : 'application/json' ,
4138 } ,
4239 body : JSON . stringify ( { firstName : 'John' } ) ,
4340 } )
44- const body = await res . text ( )
4541
46- expect ( res . status ) . toBe ( 200 )
47- expect ( body ) . toBe ( `{"firstName":"John"}` )
42+ expect . soft ( response . status ) . toBe ( 200 )
43+ await expect . soft ( response . text ( ) ) . resolves . toBe ( `{"firstName":"John"}` )
4844} )
4945
5046test ( 'reads array buffer request body as text' , async ( ) => {
51- const res = await fetch ( 'http://localhost/resource' , {
47+ const response = await fetch ( 'http://localhost/resource' , {
5248 method : 'POST' ,
5349 body : encodeBuffer ( 'hello-world' ) ,
5450 } )
55- const body = await res . text ( )
5651
57- expect ( res . status ) . toBe ( 200 )
58- expect ( body ) . toBe ( 'hello-world' )
52+ expect . soft ( response . status ) . toBe ( 200 )
53+ await expect . soft ( response . text ( ) ) . resolves . toBe ( 'hello-world' )
5954} )
6055
6156test ( 'reads null request body as empty text' , async ( ) => {
62- const res = await fetch ( 'http://localhost/resource' , {
57+ const response = await fetch ( 'http://localhost/resource' , {
6358 method : 'POST' ,
6459 body : null as any ,
6560 } )
66- const body = await res . text ( )
6761
68- expect ( res . status ) . toBe ( 200 )
69- expect ( body ) . toBe ( '' )
62+ expect . soft ( response . status ) . toBe ( 200 )
63+ await expect . soft ( response . text ( ) ) . resolves . toBe ( '' )
7064} )
7165
7266test ( 'reads undefined request body as empty text' , async ( ) => {
73- const res = await fetch ( 'http://localhost/resource' , {
67+ const response = await fetch ( 'http://localhost/resource' , {
7468 method : 'POST' ,
7569 } )
76- const body = await res . text ( )
7770
78- expect ( res . status ) . toBe ( 200 )
79- expect ( body ) . toBe ( '' )
71+ expect . soft ( response . status ) . toBe ( 200 )
72+ await expect . soft ( response . text ( ) ) . resolves . toBe ( '' )
8073} )
0 commit comments