test: enhance ClaudeUsageService tests with promise handling and exit callback

- Added an `afterEach` hook to clean up after tests in `claude-usage-service.test.ts`.
- Updated the mock for `onExit` to include an exit callback, ensuring proper handling of process termination.
- Modified the `fetchUsageData` test to await the promise resolution, preventing unhandled promise rejections.

These changes improve the reliability and robustness of the unit tests for the ClaudeUsageService.
This commit is contained in:
Kacper
2025-12-21 23:18:49 +01:00
parent 26236d3d5b
commit 0c59add31f
2 changed files with 18 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
import { useEffect } from 'react';
import { useEffect, useRef } from 'react';
interface UseSidebarAutoCollapseProps {
sidebarOpen: boolean;
@@ -9,6 +9,8 @@ export function useSidebarAutoCollapse({
sidebarOpen,
toggleSidebar,
}: UseSidebarAutoCollapseProps) {
const isMountedRef = useRef(false);
// Auto-collapse sidebar on small screens
useEffect(() => {
const mediaQuery = window.matchMedia('(max-width: 1024px)'); // lg breakpoint
@@ -20,8 +22,11 @@ export function useSidebarAutoCollapse({
}
};
// Check on mount
handleResize();
// Check on mount only
if (!isMountedRef.current) {
isMountedRef.current = true;
handleResize();
}
// Listen for changes
mediaQuery.addEventListener('change', handleResize);