Skip to content

Commit 2db0f23

Browse files
author
Sebastian Tello
committed
fix(interaction): include response body if set to empty string
1 parent 3b2e67e commit 2db0f23

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/dsl/interaction.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ describe("Interaction", () => {
8787
expect(actual.request).to.have.keys("method", "path", "query", "headers", "body");
8888
});
8989
});
90+
91+
describe("request body", () => {
92+
it("is included when an empty string is specified", () => {
93+
const actual = new Interaction().withRequest({
94+
body: "",
95+
method: HTTPMethod.GET,
96+
path: "/path",
97+
}).json();
98+
expect(actual.request).to.have.any.keys("body");
99+
});
100+
101+
it("is not included when explicitly set to undefined", () => {
102+
const actual = new Interaction().withRequest({
103+
body: undefined,
104+
method: HTTPMethod.GET,
105+
path: "/path",
106+
}).json();
107+
expect(actual.request).not.to.have.any.keys("body");
108+
});
109+
});
90110
});
91111

92112
describe("#willRespondWith", () => {
@@ -131,5 +151,27 @@ describe("Interaction", () => {
131151
expect(actual.response).to.have.keys("status", "headers", "body");
132152
});
133153
});
154+
155+
describe("response body", () => {
156+
it("is included when an empty string is specified", () => {
157+
interaction = new Interaction();
158+
interaction.willRespondWith({
159+
body: "",
160+
status: 204,
161+
});
162+
const actual = interaction.json();
163+
expect(actual.response).to.have.any.keys("body");
164+
});
165+
166+
it("is not included when explicitly set to undefined", () => {
167+
interaction = new Interaction();
168+
interaction.willRespondWith({
169+
body: undefined,
170+
status: 204,
171+
});
172+
const actual = interaction.json();
173+
expect(actual.response).not.to.have.any.keys("body");
174+
});
175+
});
134176
});
135177
});

src/dsl/interaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class Interaction {
106106
}
107107

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

0 commit comments

Comments
 (0)