Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 7fab686

Browse files
Restricts response fields used byt assertResponsesAreEqual
1 parent 8470996 commit 7fab686

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

reno/testing.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
import { assertEquals } from "../deps.ts";
22
import { AugmentedResponse } from "./router.ts";
33

4+
export function createResponseSubset(
5+
{
6+
status,
7+
statusText,
8+
cookies,
9+
headers,
10+
ok,
11+
redirected,
12+
type,
13+
}: AugmentedResponse,
14+
body: string,
15+
) {
16+
return {
17+
status,
18+
statusText,
19+
cookies,
20+
headers,
21+
ok,
22+
redirected,
23+
type,
24+
body,
25+
};
26+
}
27+
428
export function createAssertResponsesAreEqual(assertEqls: typeof assertEquals) {
529
return async function (
630
actual: AugmentedResponse,
@@ -10,15 +34,11 @@ export function createAssertResponsesAreEqual(assertEqls: typeof assertEquals) {
1034
[actual, expected].map((res) => res.text()),
1135
);
1236

37+
/* It seems that deeply comparing the requests always fails
38+
* so we instead have to match a subset of their fields. */
1339
assertEqls(
14-
{
15-
...actual,
16-
body: actualText,
17-
},
18-
{
19-
...expected,
20-
body: expectedText,
21-
},
40+
createResponseSubset(actual, actualText),
41+
createResponseSubset(expected, expectedText),
2242
);
2343
};
2444
}

reno/testing_test.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { testdouble } from "../deps.ts";
22
import type { assertEquals } from "../deps.ts";
3-
import { createAssertResponsesAreEqual } from "./testing.ts";
3+
import {
4+
createAssertResponsesAreEqual,
5+
createResponseSubset,
6+
} from "./testing.ts";
47

58
function createAssertEquals() {
69
return testdouble.func("assertEqls") as typeof assertEquals;
@@ -20,14 +23,8 @@ Deno.test({
2023

2124
testdouble.verify(
2225
assertEqls(
23-
{
24-
...a,
25-
body: "Response body A",
26-
},
27-
{
28-
...b,
29-
body: "Response body B",
30-
},
26+
createResponseSubset(a, "Response body A"),
27+
createResponseSubset(b, "Response body B"),
3128
),
3229
);
3330
},

0 commit comments

Comments
 (0)