From 8baf533c7073af60c65c1ba524886c0e127360ff Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 05:04:59 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20Add=20error=20path=20test=20?= =?UTF-8?q?for=20useUpdate=20outside=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> --- src/__tests__/context.test.ts | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/__tests__/context.test.ts diff --git a/src/__tests__/context.test.ts b/src/__tests__/context.test.ts new file mode 100644 index 00000000..1078aa65 --- /dev/null +++ b/src/__tests__/context.test.ts @@ -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(); + }); + + 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); + }); +}); From fada389339bb0b004669a640e3adbb7fa6d1177b Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 08:17:00 +0000 Subject: [PATCH 2/2] fix: apply CodeRabbit auto-fixes Fixed 1 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit --- src/__tests__/context.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/__tests__/context.test.ts b/src/__tests__/context.test.ts index 1078aa65..e18714e0 100644 --- a/src/__tests__/context.test.ts +++ b/src/__tests__/context.test.ts @@ -1,6 +1,7 @@ -import { describe, expect, test, mock, afterEach } from 'bun:test'; +import { describe, expect, test, mock, afterEach, afterAll } from 'bun:test'; // Must set __DEV__ before importing context.ts +const _origDEV = (globalThis as any).__DEV__; (globalThis as any).__DEV__ = true; const mockUseContext = mock(() => ({})); @@ -17,6 +18,10 @@ const { useUpdate } = await import('../context'); const { default: i18n } = await import('../i18n'); describe('context', () => { + afterAll(() => { + (globalThis as any).__DEV__ = _origDEV; + }); + afterEach(() => { mockUseContext.mockClear(); });