From 8c9723cb0f9dc5224c667c8265ae82c3a2f64427 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Sun, 21 May 2023 18:08:42 +0100 Subject: [PATCH] test: fix test warning regarding async suspension rendering --- src/SDKVersion.tsx | 7 ++++--- src/__tests__/sanity-check.test.tsx | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/SDKVersion.tsx b/src/SDKVersion.tsx index ce7d557..5ee234b 100644 --- a/src/SDKVersion.tsx +++ b/src/SDKVersion.tsx @@ -1,7 +1,7 @@ import { InfoOutlineIcon } from '@chakra-ui/icons'; import { Tooltip, VStack, Text, Flex } from '@chakra-ui/react'; -import { workerClientBus } from './decrypt-worker/client.ts'; -import { DECRYPTION_WORKER_ACTION_NAME } from './decrypt-worker/constants'; +import { workerClientBus } from '~/decrypt-worker/client'; +import { DECRYPTION_WORKER_ACTION_NAME } from '~/decrypt-worker/constants'; import usePromise from 'react-promise-suspense'; @@ -11,8 +11,9 @@ const getSDKVersion = async (): Promise => { export function SDKVersion() { const sdkVersion = usePromise(getSDKVersion, []); + return ( - + { +vi.mock('../decrypt-worker/client', () => { + return { + workerClientBus: { + request: vi.fn().mockResolvedValue('dummy'), + }, + }; +}); + +test('should be able to render App', async () => { renderWithProviders(); + // Should eventually load sdk version + await waitFor(() => screen.getByTestId('sdk-version')); + // Quick sanity check of known strings. expect(screen.getByText(/仅在浏览器内对文件进行解锁/i)).toBeInTheDocument(); expect(screen.getByText(/UnlockMusic 团队/i)).toBeInTheDocument();