Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit a45bfaf

Browse files
feat: checks HTTP message properties on the "expected" message
BREAKING CHANGE: Validates all expected HTTP message properties
1 parent cc1825f commit a45bfaf

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lib/next/validateMessage.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@ function validateMessage(realMessage, expectedMessage) {
1414
// for validation with the expected message.
1515
const real = normalize(coerce(realMessage));
1616

17-
// Weak coercion applies transformation only to the properties
18-
// present in the given message. We don't want to mutate user's assertion.
19-
// However, we do want to use the same coercion logic we do
20-
// for strict coercion. Thus normalization and coercion are separate.
17+
// Use weak coercion on expected message.
18+
// This means that only the properties present in expected message
19+
// will be coerced. We don't want to mutate user's assertion.
20+
// However, we want to use the same coercion logic for any coercion type.
2121
const expected = normalize(coerceWeak(expectedMessage));
2222

23-
if (real.statusCode) {
23+
if (expected.statusCode) {
2424
results.statusCode = validateStatusCode(real, expected);
2525
}
2626

27-
if (real.headers && expected.headers) {
27+
if (expected.headers) {
2828
results.headers = validateHeaders(real, expected);
2929
}
3030

31-
if (
32-
isset(real.body) &&
33-
(isset(expected.body) || isset(expected.bodySchema))
34-
) {
31+
if (isset(expected.body) || isset(expected.bodySchema)) {
3532
results.body = validateBody(real, expected);
3633
}
3734

0 commit comments

Comments
 (0)