summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/contexts/SessionContext.test.tsx
diff options
context:
space:
mode:
authorSandy Tao <[email protected]>2025-06-27 16:39:54 -0700
committerGitHub <[email protected]>2025-06-27 23:39:54 +0000
commit150df382f8e0b84aa6028622480c28186c99b8a7 (patch)
treebf2e663e90914390408202aed409a95dfd56fe57 /packages/cli/src/ui/contexts/SessionContext.test.tsx
parent19d2a0fb35ff75ebbed2dda5c8574ffcc66cd4d5 (diff)
Upgrade to Ink 6 and React 19 (#2096)
Co-authored-by: jacob314 <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/contexts/SessionContext.test.tsx')
-rw-r--r--packages/cli/src/ui/contexts/SessionContext.test.tsx26
1 files changed, 11 insertions, 15 deletions
diff --git a/packages/cli/src/ui/contexts/SessionContext.test.tsx b/packages/cli/src/ui/contexts/SessionContext.test.tsx
index e9fc33e6..fedb5341 100644
--- a/packages/cli/src/ui/contexts/SessionContext.test.tsx
+++ b/packages/cli/src/ui/contexts/SessionContext.test.tsx
@@ -6,6 +6,7 @@
import { type MutableRefObject } from 'react';
import { render } from 'ink-testing-library';
+import { renderHook } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { SessionStatsProvider, useSessionStats } from './SessionContext.js';
import { describe, it, expect, vi } from 'vitest';
@@ -223,21 +224,16 @@ describe('SessionStatsContext', () => {
});
it('should throw an error when useSessionStats is used outside of a provider', () => {
- // Suppress the expected console error during this test.
- const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ // Suppress console.error for this test since we expect an error
+ const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
- const contextRef = { current: undefined };
-
- // We expect rendering to fail, which React will catch and log as an error.
- render(<TestHarness contextRef={contextRef} />);
-
- // Assert that the first argument of the first call to console.error
- // contains the expected message. This is more robust than checking
- // the exact arguments, which can be affected by React/JSDOM internals.
- expect(errorSpy.mock.calls[0][0]).toContain(
- 'useSessionStats must be used within a SessionStatsProvider',
- );
-
- errorSpy.mockRestore();
+ try {
+ // Expect renderHook itself to throw when the hook is used outside a provider
+ expect(() => {
+ renderHook(() => useSessionStats());
+ }).toThrow('useSessionStats must be used within a SessionStatsProvider');
+ } finally {
+ consoleSpy.mockRestore();
+ }
});
});