Skip to content

Commit abc20d4

Browse files
Sebastian Tellomefellows
Sebastian Tello
authored andcommitted
fix(interaction): include response body if set to empty string
1 parent 261feb1 commit abc20d4

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/dsl/interaction.spec.ts

+50
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ describe("Interaction", () => {
9292
expect(actual.request).to.have.keys("method", "path", "query", "headers", "body");
9393
});
9494
});
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+
});
95119
});
96120

97121
describe("#willRespondWith", () => {
@@ -138,5 +162,31 @@ describe("Interaction", () => {
138162
expect(actual.response).to.have.keys("status", "headers", "body");
139163
});
140164
});
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+
});
141191
});
142192
});

src/dsl/interaction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class Interaction {
108108
}
109109

110110
this.state.response = omitBy({
111-
body: responseOpts.body || undefined,
111+
body: responseOpts.body,
112112
headers: responseOpts.headers || undefined,
113113
status: responseOpts.status,
114114
}, isNil) as ResponseOptions;

0 commit comments

Comments
 (0)