local-provider.test.js•949 B
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { getJoke } from '../../src/providers/local.js';
const mockRandom = (value) => {
vi.spyOn(Math, 'random').mockReturnValue(value);
};
describe('local provider', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('returns a programming joke when available', async () => {
mockRandom(0);
const joke = await getJoke({ category: 'programming', lang: 'en', blacklist: [] });
expect(joke.source).toBe('local-fallback');
expect(joke.category).toBe('programming');
expect(typeof joke.text).toBe('string');
});
it('falls back to same language when category missing', async () => {
mockRandom(0);
const joke = await getJoke({ category: 'spooky', lang: 'zh', blacklist: [] });
expect(joke.source).toBe('local-fallback');
expect(joke.category).toBe('programming');
expect(joke.text).toContain('程序员');
});
});