brand new unit tests finally
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m16s

This commit is contained in:
2025-11-28 09:02:26 -08:00
parent 67265edb33
commit 8fd7bb7a0b
3 changed files with 18 additions and 12 deletions

View File

@@ -59,8 +59,15 @@ describe('VoiceLabPage', () => {
await waitFor(() => {
expect(mockedAiApiClient.generateSpeechFromText).toHaveBeenCalledWith('Hello! This is a test of the text-to-speech generation.');
// Expect global.Audio to have been called (Audio is now a spy)
expect(global.Audio).toHaveBeenCalledWith(`data:audio/mpeg;base64,${mockBase64Audio}`);
});
// Wait specifically for the audio constructor call
await waitFor(() => {
expect(global.Audio).toHaveBeenCalledWith(`data:audio/mpeg;base64,${mockBase64Audio}`);
});
// Then check play
await waitFor(() => {
expect(mockAudioPlay).toHaveBeenCalled();
});

View File

@@ -2,11 +2,13 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
// Mock the nodemailer library BEFORE importing the email service.
const mockSendMail = vi.fn().mockResolvedValue({ messageId: 'default-id' });
const mockSendMail = vi.fn();
// Mock both default and named exports to cover all import styles
vi.mock('nodemailer', () => {
// Return a consistent mock object structure
// Ensure the mock returns a promise by default inside the factory to prevent startup errors
mockSendMail.mockResolvedValue({ messageId: 'default-id' });
const createTransport = vi.fn(() => ({
sendMail: mockSendMail,
}));

View File

@@ -8,15 +8,12 @@ const errorMock = vi.fn();
// Mock react-hot-toast
vi.mock('react-hot-toast', () => {
const toastMock = vi.fn();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(toastMock as any).success = (...args: any[]) => successMock(...args);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(toastMock as any).error = (...args: any[]) => errorMock(...args);
const toast = vi.fn() as any;
toast.success = successMock;
toast.error = errorMock;
return {
default: toastMock,
toast: toastMock,
default: toast,
toast,
};
});