@xtsai/x-supports
Version:
The biz-support is an library for both frontend & backend
39 lines • 1.24 kB
JavaScript
import { describe } from 'node:test';
import { chatMessagesValidate } from './json-formatter';
describe(`JSON-formatter Unit Test`, () => {
const messages = [
{
role: 'user',
content: 'hello',
},
{
role: 'assistant',
content: 'hi, i am xai!',
},
];
it('chat messages validate should no error', () => {
const json = chatMessagesValidate(JSON.stringify(messages, null, 2));
expect(json).toEqual(JSON.stringify(messages));
});
it('chat messages validate should has error "第2对话不是 assistant"', () => {
try {
const mockMessages = [
{
role: 'user',
content: 'hello',
},
{
content: 'hi, i am xai!',
},
];
mockMessages[1].role = '';
const input = JSON.stringify(mockMessages);
chatMessagesValidate(input);
}
catch (error) {
expect(error).toBeInstanceOf(Error);
expect(error.message).toBe('第2条对话不是 assistant');
}
});
});
//# sourceMappingURL=json-formatter.spec.js.map