/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react-query/test/setQueriesData.test.tsx
71 строка
2 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 userEvent from '@testing-library/user-event'; import React from 'react'; let factory: ReturnType<typeof createAppRouter>; beforeEach(() => { factory = createAppRouter(); }); afterEach(async () => { await factory.close(); }); describe('setQueriesData()', () => { test('overrides initial data', async () => { const { trpc, client, App } = factory; function MyComponent() { const utils = trpc.useUtils(); const allPostsQuery = trpc.allPosts.useQuery(undefined, { enabled: false, }); return ( <> <pre>{JSON.stringify(allPostsQuery.data ?? null, null, 4)}</pre> <button data-testid="setQueriesData" onClick={async () => { const updatedKeys = utils.allPosts.setQueriesData( undefined, {}, [ { id: 'id2', title: 'allPost.newTitle1', createdAt: Date.now(), }, { id: 'id2', title: 'allPost.newTitle2', createdAt: Date.now(), }, ], undefined, ); expect(updatedKeys.length).toBeGreaterThan(0); }} /> </> ); } const utils = render( <App> <MyComponent /> </App>, ); expect(utils.container).not.toHaveTextContent('allPost.newTitle1'); expect(utils.container).not.toHaveTextContent('allPost.newTitle2'); await userEvent.click(utils.getByTestId('setQueriesData')); await vi.waitFor(() => { expect(utils.container).toHaveTextContent('allPost.newTitle1'); expect(utils.container).toHaveTextContent('allPost.newTitle2'); }); }); });