Skip to content

Commit 007acb8

Browse files
committed
add complex pipe tests
1 parent 11d68b9 commit 007acb8

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

ark/type/__tests__/pipe.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,4 +1042,34 @@ Right: { foo: (In: string) => Out<{ [string]: $jsonObject | number | string | fa
10421042
attest<number>(t.morphed)
10431043
attest<number | undefined>(t.nested?.morphed)
10441044
})
1045+
1046+
it("complex morphs are applied on correct path", () => {
1047+
let c: null | 1
1048+
1049+
const M = type({
1050+
list: type("object")
1051+
.pipe(e => e)
1052+
.pipe(
1053+
type({
1054+
z: type("unknown").pipe(() => c)
1055+
})
1056+
)
1057+
.array(),
1058+
_: ["unknown", ":", () => true]
1059+
})
1060+
1061+
c = null
1062+
attest(() =>
1063+
M({
1064+
list: [{ z: "" }, { z: "" }]
1065+
}).toString()
1066+
).throws.snap("TypeError: Cannot read properties of null (reading 'z')")
1067+
1068+
c = 1
1069+
attest(() =>
1070+
M({
1071+
list: [{ z: "" }, { z: "" }]
1072+
}).toString()
1073+
).throws.snap("TypeError: Cannot create property 'z' on number '1'")
1074+
})
10451075
})

0 commit comments

Comments
 (0)