Files
AvDict/test/display.test.js
gdjdkid e2932476a7 Fixes: Improved unit tests for fetcher and display
- display.test.js: Added vitest import to afterEach
- fetcher.test.js: Changed from mock axios to mock child_process.execSync
- fetcher.test.js: Added mock cache.js to avoid caching interference with tests
- fetcher.test.js: Changed network failure test to expect null return
2026-03-22 12:12:00 +08:00

55 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { display } from '../lib/display.js';
const MOCK_INFO = {
id: 'SSIS-001',
title: '测试标题',
actresses: ['天使もえ'],
actors: ['男优A'],
releaseDate: '2021-01-01',
duration: '120分钟',
studio: 'SOD Create',
label: 'SOD',
director: '导演A',
series: '系列A',
tags: ['独占', '美少女'],
coverUrl: 'https://example.com/cover.jpg',
score: '4.5分',
};
describe('display.js', () => {
beforeEach(() => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});
afterEach(() => {
vi.restoreAllMocks();
});
it('display:正常调用不抛出异常', () => {
expect(() => display(MOCK_INFO)).not.toThrow();
});
it('display:输出内容包含番号', () => {
display(MOCK_INFO);
const allOutput = console.log.mock.calls.flat().join(' ');
expect(allOutput).toContain('SSIS-001');
});
it('display:输出内容包含女优名', () => {
display(MOCK_INFO);
const allOutput = console.log.mock.calls.flat().join(' ');
expect(allOutput).toContain('天使もえ');
});
it('display:raw 模式输出 JSON 字符串', () => {
display(MOCK_INFO, true);
const allOutput = console.log.mock.calls.flat().join(' ');
expect(() => JSON.parse(allOutput)).not.toThrow();
});
it('display:空字段不影响正常输出', () => {
const sparseInfo = { ...MOCK_INFO, actors: [], tags: [], coverUrl: '' };
expect(() => display(sparseInfo)).not.toThrow();
});
});