Skip to content

Commit f048068

Browse files
committed
wip(spec): rejection tests assert the issue code, path and message
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BUeRMD4VYCYUfzxTKcZFAF
1 parent 1f5811f commit f048068

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎packages/spec/src/system/i18n-report.test.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,27 @@ describe('TranslationDataSchema — reports', () => {
6868
it('refuses a bare string per report — the value is an object of `label` / `description`', () => {
6969
const result = TranslationDataSchema.safeParse({ reports: { opps_by_stage: '各阶段商机' } });
7070
expect(result.success).toBe(false);
71+
expect(result.error!.issues[0]).toMatchObject({ code: 'invalid_type', path: ['reports', 'opps_by_stage'] });
7172
});
7273

7374
it('renames the singular spelling onto the group, and `name` / `title` onto `label`', () => {
74-
expect(() => TranslationDataSchema.parse({ report: { r: { label: 'x' } } })).toThrow(/reports/);
75-
expect(() => TranslationItemSchema.parse({ locale: 'en', report: { r: { label: 'x' } } })).toThrow(/reports/);
76-
expect(() => TranslationDataSchema.parse({ reports: { r: { title: 'x' } } })).toThrow(/label/);
77-
expect(() => TranslationDataSchema.parse({ reports: { r: { name: 'x' } } })).toThrow(/label/);
75+
const issueOf = (result: { success: boolean; error?: { issues: any[] } }) => {
76+
expect(result.success).toBe(false);
77+
return result.error!.issues[0];
78+
};
79+
for (const result of [
80+
TranslationDataSchema.safeParse({ report: { r: { label: 'x' } } }),
81+
TranslationItemSchema.safeParse({ locale: 'en', report: { r: { label: 'x' } } }),
82+
]) {
83+
const issue = issueOf(result);
84+
expect(issue).toMatchObject({ code: 'unrecognized_keys', keys: ['report'], path: [] });
85+
expect(issue.message).toContain('`report` → `reports`');
86+
}
87+
for (const key of ['title', 'name']) {
88+
const issue = issueOf(TranslationDataSchema.safeParse({ reports: { r: { [key]: 'x' } } }));
89+
expect(issue).toMatchObject({ code: 'unrecognized_keys', keys: [key], path: ['reports', 'r'] });
90+
expect(issue.message).toContain(`\`${key}\` → \`label\``);
91+
}
7892
});
7993
});
8094

0 commit comments

Comments
 (0)