@@ -3783,6 +3783,65 @@ describe('Routes', () => {
3783
3783
} )
3784
3784
} )
3785
3785
3786
+ // Set custom status message/reason phrase from http response
3787
+ // https://github.com/cypress-io/cypress/issues/16973
3788
+ it ( 'set custom status message when reason phrase is set' , function ( ) {
3789
+ nock ( this . server . remoteStates . current ( ) . origin )
3790
+ . post ( '/companies/validate' , {
3791
+ payload : { name : 'Brian' } ,
3792
+ } )
3793
+ . reply ( 400 , function ( uri , requestBody ) {
3794
+ this . req . response . statusMessage = 'This is the custom status message'
3795
+
3796
+ return {
3797
+ status : 400 ,
3798
+ message : 'This is the reply body' ,
3799
+ }
3800
+ } )
3801
+
3802
+ return this . rp ( {
3803
+ method : 'POST' ,
3804
+ url : 'http://localhost:8000/companies/validate' ,
3805
+ json : true ,
3806
+ body : {
3807
+ payload : { name : 'Brian' } ,
3808
+ } ,
3809
+ headers : {
3810
+ 'x-cypress-status' : '400' ,
3811
+ } ,
3812
+ } )
3813
+ . then ( ( res ) => {
3814
+ expect ( res . statusCode ) . to . eq ( 400 )
3815
+ expect ( res . statusMessage ) . to . eq ( 'This is the custom status message' )
3816
+ } )
3817
+ } )
3818
+
3819
+ // use default status message/reason phrase correspond to status code, from http response
3820
+ // https://github.com/cypress-io/cypress/issues/16973
3821
+ it ( 'uses default status message when reason phrase is not set' , function ( ) {
3822
+ nock ( this . server . remoteStates . current ( ) . origin )
3823
+ . post ( '/companies/validate' , {
3824
+ payload : { name : 'Brian' } ,
3825
+ } )
3826
+ . reply ( 400 )
3827
+
3828
+ return this . rp ( {
3829
+ method : 'POST' ,
3830
+ url : 'http://localhost:8000/companies/validate' ,
3831
+ json : true ,
3832
+ body : {
3833
+ payload : { name : 'Brian' } ,
3834
+ } ,
3835
+ headers : {
3836
+ 'x-cypress-status' : '400' ,
3837
+ } ,
3838
+ } )
3839
+ . then ( ( res ) => {
3840
+ expect ( res . statusCode ) . to . eq ( 400 )
3841
+ expect ( res . statusMessage ) . to . eq ( 'Bad Request' )
3842
+ } )
3843
+ } )
3844
+
3786
3845
it ( 'hands back 201 status codes' , function ( ) {
3787
3846
nock ( this . server . remoteStates . current ( ) . origin )
3788
3847
. post ( '/companies/validate' , {
0 commit comments