Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/__tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, test, mock, afterEach } from 'bun:test';

// Must set __DEV__ before importing context.ts
(globalThis as any).__DEV__ = true;

const mockUseContext = mock(() => ({}));

mock.module('react', () => {
return {
createContext: mock((defaultValue) => defaultValue),
useContext: mockUseContext,
};
});

// Import context after setting up mocks
const { useUpdate } = await import('../context');
const { default: i18n } = await import('../i18n');

describe('context', () => {
afterEach(() => {
mockUseContext.mockClear();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

test('useUpdate throws error when used outside UpdateProvider in __DEV__', () => {
mockUseContext.mockReturnValue({});

expect(() => useUpdate()).toThrow(i18n.t('error_use_update_outside_provider'));
});

test('useUpdate returns context when used inside UpdateProvider', () => {
const mockContext = { client: {} };
mockUseContext.mockReturnValue(mockContext);

expect(useUpdate()).toBe(mockContext as any);
});
});