fix: test

This commit is contained in:
Louis 2025-08-14 14:30:43 +07:00
parent aa8fb0464c
commit dcb46174ff
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -48,6 +48,12 @@ Object.defineProperty(window, 'core', {
writable: true, writable: true,
}) })
// Mock global AUTO_UPDATER_DISABLED
Object.defineProperty(global, 'AUTO_UPDATER_DISABLED', {
value: false,
writable: true,
})
import { isDev } from '@/lib/utils' import { isDev } from '@/lib/utils'
import { check } from '@tauri-apps/plugin-updater' import { check } from '@tauri-apps/plugin-updater'
import { events } from '@janhq/core' import { events } from '@janhq/core'
@ -251,11 +257,14 @@ describe('useAppUpdater', () => {
downloadAndInstall: mockDownloadAndInstall, downloadAndInstall: mockDownloadAndInstall,
} }
// Mock check to return the update
mockCheck.mockResolvedValue(mockUpdate)
const { result } = renderHook(() => useAppUpdater()) const { result } = renderHook(() => useAppUpdater())
// Set update info first // Set update info first by calling checkForUpdate
act(() => { await act(async () => {
result.current.updateState.updateInfo = mockUpdate await result.current.checkForUpdate()
}) })
// Mock the download and install process // Mock the download and install process
@ -296,11 +305,14 @@ describe('useAppUpdater', () => {
downloadAndInstall: mockDownloadAndInstall, downloadAndInstall: mockDownloadAndInstall,
} }
// Mock check to return the update
mockCheck.mockResolvedValue(mockUpdate)
const { result } = renderHook(() => useAppUpdater()) const { result } = renderHook(() => useAppUpdater())
// Set update info first // Set update info first by calling checkForUpdate
act(() => { await act(async () => {
result.current.updateState.updateInfo = mockUpdate await result.current.checkForUpdate()
}) })
mockDownloadAndInstall.mockRejectedValue(new Error('Download failed')) mockDownloadAndInstall.mockRejectedValue(new Error('Download failed'))
@ -338,11 +350,14 @@ describe('useAppUpdater', () => {
downloadAndInstall: mockDownloadAndInstall, downloadAndInstall: mockDownloadAndInstall,
} }
// Mock check to return the update
mockCheck.mockResolvedValue(mockUpdate)
const { result } = renderHook(() => useAppUpdater()) const { result } = renderHook(() => useAppUpdater())
// Set update info first // Set update info first by calling checkForUpdate
act(() => { await act(async () => {
result.current.updateState.updateInfo = mockUpdate await result.current.checkForUpdate()
}) })
mockDownloadAndInstall.mockImplementation(async (progressCallback) => { mockDownloadAndInstall.mockImplementation(async (progressCallback) => {