feat: update RefreshControl mocks in tests and improve error handling in useChangePassword hook

This commit is contained in:
imeepos
2026-01-27 17:18:54 +08:00
parent 8f00d4644a
commit cd1a4f6841
13 changed files with 49 additions and 33 deletions

View File

@@ -8,7 +8,7 @@
*/
import { renderHook, waitFor, act } from '@testing-library/react-native'
import { useWorksSearch } from '@/hooks/use-works-search'
import { useWorksSearch, type WorksCategory } from '@/hooks/use-works-search'
import { root } from '@repo/core'
import { TemplateGenerationController } from '@repo/sdk'
@@ -21,15 +21,15 @@ jest.mock('@repo/core', () => ({
// Mock @tanstack/react-query before importing the hook
const mockRefetch = jest.fn()
const mockUseQuery = jest.fn(() => ({
data: undefined,
isLoading: false,
error: null,
refetch: mockRefetch,
}))
const mockUseQuery = jest.fn()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockUseQueryImpl = (...args: any[]) => {
return mockUseQuery(args[0], args[1])
}
jest.mock('@tanstack/react-query', () => ({
useQuery: jest.fn((args) => mockUseQuery(args)),
useQuery: mockUseQueryImpl,
}))
describe('useWorksSearch', () => {
@@ -267,16 +267,16 @@ describe('useWorksSearch', () => {
})
const { result, rerender } = renderHook(
({ keyword, category }) => useWorksSearch({ keyword, category }),
({ keyword, category }: { keyword: string; category?: WorksCategory }) => useWorksSearch({ keyword, category }),
{
initialProps: { keyword: '测试', category: '萌宠' as const },
initialProps: { keyword: '测试', category: '萌宠' },
}
)
expect(result.current.works).toEqual(mockData1.data)
// Switch category
rerender({ keyword: '测试', category: '写真' as const })
rerender({ keyword: '测试', category: '写真' })
expect(result.current.works).toEqual(mockData2.data)
})