Files

29 lines
893 B
TypeScript

import { describe, it, expect } from 'vitest';
import { newsSchema } from '../src/content/schemas';
describe('newsSchema', () => {
it('accepts valid frontmatter and coerces date', () => {
const parsed = newsSchema.parse({
title: '官网基座启动',
date: '2026-07-23',
category: '公告',
});
expect(parsed.title).toBe('官网基座启动');
expect(parsed.date).toEqual(new Date('2026-07-23'));
expect(parsed.category).toBe('公告');
});
it('defaults category to 未分类', () => {
const parsed = newsSchema.parse({ title: '测试', date: '2026-07-23' });
expect(parsed.category).toBe('未分类');
});
it('rejects missing title', () => {
expect(() => newsSchema.parse({ date: '2026-07-23' })).toThrow();
});
it('rejects missing date', () => {
expect(() => newsSchema.parse({ title: '测试' })).toThrow();
});
});