From dcb46174ff03b9a3380079eefb452a8428c2e7e2 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 14 Aug 2025 14:30:43 +0700 Subject: [PATCH] fix: test --- .../src/hooks/__tests__/useAppUpdater.test.ts | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/web-app/src/hooks/__tests__/useAppUpdater.test.ts b/web-app/src/hooks/__tests__/useAppUpdater.test.ts index 250c37fed..2c736f0f3 100644 --- a/web-app/src/hooks/__tests__/useAppUpdater.test.ts +++ b/web-app/src/hooks/__tests__/useAppUpdater.test.ts @@ -48,6 +48,12 @@ Object.defineProperty(window, 'core', { writable: true, }) +// Mock global AUTO_UPDATER_DISABLED +Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', { + value: false, + writable: true, +}) + import { isDev } from '@/lib/utils' import { check } from '@tauri-apps/plugin-updater' import { events } from '@janhq/core' @@ -251,11 +257,14 @@ describe('useAppUpdater', () => { downloadAndInstall: mockDownloadAndInstall, } + // Mock check to return the update + mockCheck.mockResolvedValue(mockUpdate) + const { result } = renderHook(() => useAppUpdater()) - // Set update info first - act(() => { - result.current.updateState.updateInfo = mockUpdate + // Set update info first by calling checkForUpdate + await act(async () => { + await result.current.checkForUpdate() }) // Mock the download and install process @@ -296,11 +305,14 @@ describe('useAppUpdater', () => { downloadAndInstall: mockDownloadAndInstall, } + // Mock check to return the update + mockCheck.mockResolvedValue(mockUpdate) + const { result } = renderHook(() => useAppUpdater()) - // Set update info first - act(() => { - result.current.updateState.updateInfo = mockUpdate + // Set update info first by calling checkForUpdate + await act(async () => { + await result.current.checkForUpdate() }) mockDownloadAndInstall.mockRejectedValue(new Error('Download failed')) @@ -338,11 +350,14 @@ describe('useAppUpdater', () => { downloadAndInstall: mockDownloadAndInstall, } + // Mock check to return the update + mockCheck.mockResolvedValue(mockUpdate) + const { result } = renderHook(() => useAppUpdater()) - // Set update info first - act(() => { - result.current.updateState.updateInfo = mockUpdate + // Set update info first by calling checkForUpdate + await act(async () => { + await result.current.checkForUpdate() }) mockDownloadAndInstall.mockImplementation(async (progressCallback) => {