@@ -41,8 +41,9 @@ test('mocks a response with a text body', async ({ network, page }) => {
4141
4242 await page . goto ( '/' )
4343
44- const response = await page . evaluate ( ( ) => {
45- return fetch ( '/text' ) . then ( ( response ) => response . text ( ) )
44+ const response = await page . evaluate ( async ( ) => {
45+ const response = await fetch ( '/text' )
46+ return response . text ( )
4647 } )
4748
4849 expect ( response ) . toBe ( 'Hello world!' )
@@ -57,8 +58,9 @@ test('mocks a response with a json body', async ({ network, page }) => {
5758
5859 await page . goto ( '/' )
5960
60- const response = await page . evaluate ( ( ) => {
61- return fetch ( '/json' ) . then ( ( response ) => response . json ( ) )
61+ const response = await page . evaluate ( async ( ) => {
62+ const response = await fetch ( '/json' )
63+ return response . json ( )
6264 } )
6365
6466 expect ( response ) . toEqual ( { hello : 'world' } )
@@ -75,15 +77,10 @@ test('mocks a response with an ArrayBuffer body', async ({ network, page }) => {
7577
7678 await page . goto ( '/' )
7779
78- const response = await page . evaluate ( ( ) => {
79- return (
80- fetch ( '/arrayBuffer' )
81- . then ( ( response ) => response . arrayBuffer ( ) )
82- /**
83- * @note Playwright doesn't support returning `ArrayBuffer` directly.
84- */
85- . then ( ( data ) => new TextDecoder ( ) . decode ( data ) )
86- )
80+ const response = await page . evaluate ( async ( ) => {
81+ const response = await fetch ( '/arrayBuffer' )
82+ const data = await response . arrayBuffer ( )
83+ return new TextDecoder ( ) . decode ( data )
8784 } )
8885
8986 expect ( response ) . toBe ( 'hello world' )
@@ -100,10 +97,10 @@ test('mocks a response with an FormData body', async ({ network, page }) => {
10097
10198 await page . goto ( '/' )
10299
103- const response = await page . evaluate ( ( ) => {
104- return fetch ( '/formData' )
105- . then ( ( response ) => response . formData ( ) )
106- . then ( ( data ) => Array . from ( data . entries ( ) ) )
100+ const response = await page . evaluate ( async ( ) => {
101+ const response = await fetch ( '/formData' )
102+ const data = await response . formData ( )
103+ return Array . from ( data . entries ( ) )
107104 } )
108105
109106 expect ( response ) . toEqual ( [ [ 'hello' , 'world' ] ] )
@@ -126,8 +123,9 @@ test('mocks a response with a stream', async ({ network, page }) => {
126123
127124 await page . goto ( '/' )
128125
129- const response = await page . evaluate ( ( ) => {
130- return fetch ( '/stream' ) . then ( ( response ) => response . text ( ) )
126+ const response = await page . evaluate ( async ( ) => {
127+ const response = await fetch ( '/stream' )
128+ return response . text ( )
131129 } )
132130
133131 expect ( response ) . toBe ( 'hello world' )
0 commit comments