@@ -92,6 +92,30 @@ describe("Interaction", () => {
92
92
expect ( actual . request ) . to . have . keys ( "method" , "path" , "query" , "headers" , "body" ) ;
93
93
} ) ;
94
94
} ) ;
95
+
96
+ describe ( "request body" , ( ) => {
97
+ it ( "is included when an empty string is specified" , ( ) => {
98
+ const actual = new Interaction ( )
99
+ . uponReceiving ( "request" )
100
+ . withRequest ( {
101
+ body : "" ,
102
+ method : HTTPMethod . GET ,
103
+ path : "/path" ,
104
+ } ) . json ( ) ;
105
+ expect ( actual . request ) . to . have . any . keys ( "body" ) ;
106
+ } ) ;
107
+
108
+ it ( "is not included when explicitly set to undefined" , ( ) => {
109
+ const actual = new Interaction ( )
110
+ . uponReceiving ( "request" )
111
+ . withRequest ( {
112
+ body : undefined ,
113
+ method : HTTPMethod . GET ,
114
+ path : "/path" ,
115
+ } ) . json ( ) ;
116
+ expect ( actual . request ) . not . to . have . any . keys ( "body" ) ;
117
+ } ) ;
118
+ } ) ;
95
119
} ) ;
96
120
97
121
describe ( "#willRespondWith" , ( ) => {
@@ -138,5 +162,31 @@ describe("Interaction", () => {
138
162
expect ( actual . response ) . to . have . keys ( "status" , "headers" , "body" ) ;
139
163
} ) ;
140
164
} ) ;
165
+
166
+ describe ( "response body" , ( ) => {
167
+ it ( "is included when an empty string is specified" , ( ) => {
168
+ interaction = new Interaction ( ) ;
169
+ interaction
170
+ . uponReceiving ( "request" )
171
+ . willRespondWith ( {
172
+ body : "" ,
173
+ status : 204 ,
174
+ } ) ;
175
+ const actual = interaction . json ( ) ;
176
+ expect ( actual . response ) . to . have . any . keys ( "body" ) ;
177
+ } ) ;
178
+
179
+ it ( "is not included when explicitly set to undefined" , ( ) => {
180
+ interaction = new Interaction ( ) ;
181
+ interaction
182
+ . uponReceiving ( "request" )
183
+ . willRespondWith ( {
184
+ body : undefined ,
185
+ status : 204 ,
186
+ } ) ;
187
+ const actual = interaction . json ( ) ;
188
+ expect ( actual . response ) . not . to . have . any . keys ( "body" ) ;
189
+ } ) ;
190
+ } ) ;
141
191
} ) ;
142
192
} ) ;
0 commit comments