Skip to content

Commit

Permalink
feat(vae): VaeError message 优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Aug 24, 2023
1 parent 4f3b1aa commit aa10486
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vae/VaeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class VaeError extends Error {
name = 'VaeError'

constructor(public issues: VaeIssue[]) {
super()
super(VaeError.messageFromIssues(issues))
}

static messageFromIssues(issues: VaeIssue[]) {
return issues.map(issue => issue.message).join('; ')
}
}
4 changes: 4 additions & 0 deletions src/vae/__snapshots__/vae.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@ Object {
}
`;

exports[`vae parseOrThrow 1`] = `".应至少包含3位字符"`;

exports[`vae parseOrThrow 2`] = `"id应必填; name应至少包含3位字符"`;

exports[`vae pickFields, omitFields 1`] = `
Object {
"data": Object {
Expand Down
19 changes: 19 additions & 0 deletions src/vae/vae.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,4 +719,23 @@ describe('vae', () => {
),
).toMatchSnapshot()
})

test('parseOrThrow', () => {
expect(() =>
v.string().min(3).parseOrThrow('12'),
).toThrowErrorMatchingSnapshot()
expect(() =>
v
.object({
id: v.number().required(),
name: v.string().min(3).regex(/^56/),
})
.parseOrThrow(
// @ts-expect-error
{
name: '12',
},
),
).toThrowErrorMatchingSnapshot()
})
})

0 comments on commit aa10486

Please sign in to comment.