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

This commit is contained in:
2025-11-28 13:05:35 -08:00
parent ee6440de1b
commit 00d20751af
2 changed files with 21 additions and 13 deletions

View File

@@ -129,7 +129,12 @@ describe('VoiceLabPage', () => {
// Wait for the Replay button to appear. This confirms that the async operation completed
// and the state update (setAudioPlayer) has triggered a re-render.
const replayButton = await screen.findByRole('button', { name: /replay/i }, { timeout: 2000 });
// We use findByText which is often more robust for text content than role lookup if aria-labels aren't perfect.
const replayButton = await screen.findByText(/Replay/i, { selector: 'button' }).catch((e) => {
console.log('[TEST FAILURE DEBUG] Replay button not found. Dumping DOM:');
screen.debug();
throw e;
});
// Verify initial play happened during generation
expect(mockAudioPlay).toHaveBeenCalledTimes(1);

View File

@@ -1,18 +1,23 @@
// src/services/notificationService.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { notifySuccess, notifyError } from './notificationService';
import toast from 'react-hot-toast';
// Use vi.hoisted to ensure we access the exact same spy references
const mocks = vi.hoisted(() => ({
success: vi.fn(),
error: vi.fn(),
}));
// Mock react-hot-toast
// The factory returns a default export which is a function with attached methods
vi.mock('react-hot-toast', () => {
const toastFn = vi.fn() as any;
toastFn.success = vi.fn();
toastFn.error = vi.fn();
const toastFn = vi.fn() as any; // Cast to any to allow adding properties
toastFn.success = mocks.success;
toastFn.error = mocks.error;
return {
__esModule: true, // Handle ES module interop
default: toastFn,
toast: toastFn, // Also mock the named export
// Some environments/transpilers might look for named exports or specific interop
__esModule: true,
};
});
@@ -26,9 +31,8 @@ describe('notificationService', () => {
const message = 'Operation completed successfully!';
notifySuccess(message);
// Assert directly on the imported mock's property
expect(toast.success).toHaveBeenCalledTimes(1);
expect(toast.success).toHaveBeenCalledWith(
expect(mocks.success).toHaveBeenCalledTimes(1);
expect(mocks.success).toHaveBeenCalledWith(
message,
expect.objectContaining({
style: expect.any(Object),
@@ -46,9 +50,8 @@ describe('notificationService', () => {
const message = 'An unexpected error occurred.';
notifyError(message);
// Assert directly on the imported mock's property
expect(toast.error).toHaveBeenCalledTimes(1);
expect(toast.error).toHaveBeenCalledWith(
expect(mocks.error).toHaveBeenCalledTimes(1);
expect(mocks.error).toHaveBeenCalledWith(
message,
expect.objectContaining({
style: expect.any(Object),