@@ -12,12 +12,14 @@ describe('fetch middleware', () => {
1212 } ) ;
1313
1414 nock ( 'http://example.com' )
15+ . persist ( )
16+ . replyContentLength ( )
1517 . get ( '/server-error' )
1618 . reply ( 503 , '' ) ;
1719
1820 const middleware = require ( '../../../lib/fetch/middleware' ) ;
1921
20- expect ( middleware ( { } , { headers : { } } ) ) . rejects . toThrow ( ) ;
22+ await expect ( middleware ( { } , { headers : { } } ) ) . rejects . toThrow ( 'Response code 503' ) ;
2123 } ) ;
2224
2325 test ( 'rejects promise when resource is not found' , async ( ) => {
@@ -26,12 +28,14 @@ describe('fetch middleware', () => {
2628 } ) ;
2729
2830 nock ( 'http://example.com' )
31+ . persist ( )
32+ . replyContentLength ( )
2933 . get ( '/not-found' )
3034 . reply ( 404 , '' ) ;
3135
3236 const middleware = require ( '../../../lib/fetch/middleware' ) ;
3337
34- expect ( middleware ( { } , { headers : { } } ) ) . rejects . toThrow ( ) ;
38+ await expect ( middleware ( { } , { headers : { } } ) ) . rejects . toThrow ( 'Response code 404' ) ;
3539 } ) ;
3640
3741 test ( 'fills response object with origin response headers' , async ( ) => {
@@ -41,7 +45,7 @@ describe('fetch middleware', () => {
4145
4246 nock ( 'http://example.com' )
4347 . get ( '/origin-response-headers' )
44- . reply ( 200 , '' , { 'content-type' : 'text/html' } ) ;
48+ . reply ( 200 , '' , { 'content-type' : 'text/html' , 'content-length' : 0 } ) ;
4549
4650 const middleware = require ( '../../../lib/fetch/middleware' ) ;
4751 const { response } = await middleware ( {
@@ -59,7 +63,7 @@ describe('fetch middleware', () => {
5963
6064 nock ( 'http://example.com' )
6165 . get ( '/origin-response-headers' )
62- . reply ( 200 , '' , { 'content-type' : 'text/html' } ) ;
66+ . reply ( 200 , '' , { 'content-type' : 'text/html' , 'content-length' : '0' } ) ;
6367
6468 const middleware = require ( '../../../lib/fetch/middleware' ) ;
6569 const { response } = await middleware ( {
@@ -79,7 +83,7 @@ describe('fetch middleware', () => {
7983
8084 nock ( 'http://example.com' )
8185 . get ( '/origin-response-headers' )
82- . reply ( 200 , body , { 'content-type' : 'text/html' } ) ;
86+ . reply ( 200 , body , { 'content-type' : 'text/html' , 'content-length' : body . length . toString ( ) } ) ;
8387
8488 const middleware = require ( '../../../lib/fetch/middleware' ) ;
8589 const { response } = await middleware ( {
@@ -100,7 +104,7 @@ describe('fetch middleware', () => {
100104 . reply ( function ( uri , requestBody , cb ) {
101105 expect ( this . req . headers [ 'accept-encoding' ] ) . toBe ( 'text/html' ) ;
102106
103- cb ( null , [ 200 , '' , { } ] ) ;
107+ cb ( null , [ 200 , '' , { 'content-length' : '0' } ] ) ;
104108 } ) ;
105109
106110 const middleware = require ( '../../../lib/fetch/middleware' ) ;
@@ -128,7 +132,7 @@ describe('fetch middleware', () => {
128132 . reply ( function ( uri , requestBody , cb ) {
129133 expect ( this . req . headers [ 'host' ] ) . toBe ( 'example.com' ) ;
130134
131- cb ( null , [ 200 , '' , { } ] ) ;
135+ cb ( null , [ 200 , '' , { 'content-length' : '0' } ] ) ;
132136 } ) ;
133137
134138 const middleware = require ( '../../../lib/fetch/middleware' ) ;
0 commit comments