This repository was archived by the owner on Jun 27, 2023. It is now read-only.
File tree 2 files changed +34
-17
lines changed
2 files changed +34
-17
lines changed Original file line number Diff line number Diff line change 1
1
import { assertEquals } from "../deps.ts" ;
2
2
import { AugmentedResponse } from "./router.ts" ;
3
3
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
+
4
28
export function createAssertResponsesAreEqual ( assertEqls : typeof assertEquals ) {
5
29
return async function (
6
30
actual : AugmentedResponse ,
@@ -10,15 +34,11 @@ export function createAssertResponsesAreEqual(assertEqls: typeof assertEquals) {
10
34
[ actual , expected ] . map ( ( res ) => res . text ( ) ) ,
11
35
) ;
12
36
37
+ /* It seems that deeply comparing the requests always fails
38
+ * so we instead have to match a subset of their fields. */
13
39
assertEqls (
14
- {
15
- ...actual ,
16
- body : actualText ,
17
- } ,
18
- {
19
- ...expected ,
20
- body : expectedText ,
21
- } ,
40
+ createResponseSubset ( actual , actualText ) ,
41
+ createResponseSubset ( expected , expectedText ) ,
22
42
) ;
23
43
} ;
24
44
}
Original file line number Diff line number Diff line change 1
1
import { testdouble } from "../deps.ts" ;
2
2
import type { assertEquals } from "../deps.ts" ;
3
- import { createAssertResponsesAreEqual } from "./testing.ts" ;
3
+ import {
4
+ createAssertResponsesAreEqual ,
5
+ createResponseSubset ,
6
+ } from "./testing.ts" ;
4
7
5
8
function createAssertEquals ( ) {
6
9
return testdouble . func ( "assertEqls" ) as typeof assertEquals ;
@@ -20,14 +23,8 @@ Deno.test({
20
23
21
24
testdouble . verify (
22
25
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" ) ,
31
28
) ,
32
29
) ;
33
30
} ,
You can’t perform that action at this time.
0 commit comments