Skip to content

Commit

Permalink
add unit error message special case for operands that serialize to sa…
Browse files Browse the repository at this point in the history
…me value (#954)
  • Loading branch information
ShawnMorreau authored May 17, 2024
1 parent d9da6b4 commit 2633783
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ark/schema/roots/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const unitImplementation: nodeImplementationOf<UnitDeclaration> =
},
normalize: schema => schema,
defaults: {
description: node => printable(node.unit)
description: node => printable(node.unit),
problem: ({ expected, actual }) =>
`${expected === actual ? `must be reference equal to ${expected} (serialized to the same value)` : `must be ${expected} (was ${actual})`}`
},
intersections: {
unit: (l, r) => Disjoint.from("unit", l, r),
Expand Down
7 changes: 7 additions & 0 deletions ark/type/__tests__/objectLiteral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ contextualize(
})
})

it("serializes to same value but not reference equal", () => {
const t = type("===", {})
attest(t({}).toString()).snap(
"must be reference equal to {} (serialized to the same value)"
)
})

it("error in obj that has tuple that writes error at proper path", () => {
// @ts-expect-error
attest(() => type({ "a?": ["string", ["stringx", "?"]] }))
Expand Down

0 comments on commit 2633783

Please sign in to comment.