From e8a8beb4cb2090a5c892a11dafdbe8acf980a6a1 Mon Sep 17 00:00:00 2001 From: Torben Sorensen Date: Sat, 29 Nov 2025 16:39:36 -0800 Subject: [PATCH] more TS fixes + tests --- src/components/FlyerCorrectionTool.test.tsx | 15 ++++++++++----- src/routes/public.routes.test.ts | 2 +- src/routes/system.test.ts | 2 +- src/services/notificationService.ts | 11 +++++++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/components/FlyerCorrectionTool.test.tsx b/src/components/FlyerCorrectionTool.test.tsx index 60bbadcd..8ea821f4 100644 --- a/src/components/FlyerCorrectionTool.test.tsx +++ b/src/components/FlyerCorrectionTool.test.tsx @@ -36,11 +36,16 @@ describe('FlyerCorrectionTool', () => { ) as Mocked; // Mock canvas methods for jsdom environment - window.HTMLCanvasElement.prototype.getContext = () => ({ - clearRect: vi.fn(), - strokeRect: vi.fn(), - setLineDash: vi.fn(), - } as any); + window.HTMLCanvasElement.prototype.getContext = vi.fn((contextId: string) => { + if (contextId === '2d') { + return { + clearRect: vi.fn(), + strokeRect: vi.fn(), + setLineDash: vi.fn(), + } as unknown as CanvasRenderingContext2D; + } + return null; + }) as any; }); it('should not render when isOpen is false', () => { diff --git a/src/routes/public.routes.test.ts b/src/routes/public.routes.test.ts index e4c1e4c0..609ad138 100644 --- a/src/routes/public.routes.test.ts +++ b/src/routes/public.routes.test.ts @@ -1,5 +1,5 @@ // src/routes/public.test.ts -import { describe, it, expect, vi, beforeEach, type Mocked, type Mock } from 'vitest'; +import { describe, it, expect, vi, beforeEach, type Mocked } from 'vitest'; import supertest from 'supertest'; import express from 'express'; import publicRouter from './public'; // Import the router we want to test diff --git a/src/routes/system.test.ts b/src/routes/system.test.ts index 2a2daf6d..7c74eaa9 100644 --- a/src/routes/system.test.ts +++ b/src/routes/system.test.ts @@ -1,5 +1,5 @@ // src/routes/system.test.ts -import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; import supertest from 'supertest'; import express from 'express'; import type { ExecException } from 'child_process'; diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index ffd0caef..4244ee1b 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -1,11 +1,14 @@ // src/services/notificationService.ts import toast, { ToastOptions } from 'react-hot-toast'; +// Define a type to safely handle potential CJS/ESM interop issues where the module is nested under a `default` property. +type ToastWithDefault = typeof toast & { default?: typeof toast }; + console.log('[NotificationService] Module loaded.'); console.log('[NotificationService] Imported toast object type:', typeof toast); console.log('[NotificationService] Imported toast keys:', Object.keys(toast || {})); -if (toast && (toast as any).default) { - console.log('[NotificationService] Has .default property:', Object.keys((toast as any).default)); +if (toast && (toast as ToastWithDefault).default) { + console.log('[NotificationService] Has .default property:', Object.keys((toast as ToastWithDefault).default || {})); } /** @@ -36,9 +39,9 @@ export const notifySuccess = (message: string) => { if (typeof toast.success !== 'function') { console.error('[NotificationService] CRITICAL: toast.success is not a function. It is:', typeof toast.success); // Fallback check for default property (common in CJS/ESM interop issues) - if ((toast as any).default && typeof (toast as any).default.success === 'function') { + if ((toast as ToastWithDefault).default && typeof (toast as ToastWithDefault).default?.success === 'function') { console.warn('[NotificationService] Found success on .default, using that instead.'); - (toast as any).default.success(message, { ...commonToastOptions, iconTheme: { primary: '#10B981', secondary: '#fff' } }); + (toast as ToastWithDefault).default?.success(message, { ...commonToastOptions, iconTheme: { primary: '#10B981', secondary: '#fff' } }); return; } }