/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react-query/test/formatError.test.tsx
55 строк
1 KB
Alex / KATT
chore: remove `waitFor` from testing (#6221)
19 мар 2025, 20:23
Не верифицирован
19 мар 2025, 20:23
b6c6ddb
Код
Авторство
О чём код?
import { createAppRouter } from './__testHelpers'; import { render } from '@testing-library/react'; import type { DefaultErrorShape } from '@trpc/server/unstable-core-do-not-import'; import React, { useEffect } from 'react'; let factory: ReturnType<typeof createAppRouter>; beforeEach(() => { factory = createAppRouter(); }); afterEach(async () => { await factory.close(); }); test('react types test', async () => { const { trpc, App } = factory; function MyComponent() { const mutation = trpc.addPost.useMutation(); useEffect(() => { mutation.mutate({ title: 123 as any }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); if (mutation.error?.shape) { expectTypeOf(mutation.error.shape).toMatchTypeOf< DefaultErrorShape & { $test: string; } >(); expectTypeOf(mutation.error.shape).toMatchTypeOf< DefaultErrorShape & { $test: string; } >(); return ( <pre data-testid="err"> {JSON.stringify(mutation.error.shape.zodError, null, 2)} </pre> ); } return <></>; } const utils = render( <App> <MyComponent /> </App>, ); await vi.waitFor(() => { expect(utils.container).toHaveTextContent('fieldErrors'); expect(utils.getByTestId('err').innerText).toMatchInlineSnapshot( `undefined`, ); }); });