diff --git a/src/components/molecules/Task.spec.tsx b/src/components/molecules/Task.spec.tsx index 410ae809..a477c344 100644 --- a/src/components/molecules/Task.spec.tsx +++ b/src/components/molecules/Task.spec.tsx @@ -3,7 +3,6 @@ import React from 'react'; import { loadNowDate, renderWithQueryProvider, - resolveWithDelay, withMutedReactQueryLogger, } from '../../lib/test/helpers'; import userEvent from '@testing-library/user-event'; @@ -14,6 +13,7 @@ import { editTask } from '../../lib/api/editTask'; import { screen } from '@testing-library/react'; import { vi, Mock, expect, it, describe, beforeEach } from 'vitest'; import { queryTaskCheckbox } from '../../lib/test/queries'; +import loadControlledPromise from '../../lib/test/loadControlledPromise'; vi.mock('../../lib/api/updateTask'); vi.mock('date-fns'); @@ -260,7 +260,7 @@ describe('Task component', () => { }); it('shows loading indicator on edit save', async () => { - resolveWithDelay(mockEditTask); + const { resolve } = loadControlledPromise(editTask); renderTask(); @@ -271,6 +271,8 @@ describe('Task component', () => { userEvent.click(screen.getByText('Save')); await screen.findByRole('progressbar'); + + resolve(); }); it('closes edit dialog on save', async () => { diff --git a/src/lib/getUnloadMessage.spec.tsx b/src/lib/getUnloadMessage.spec.tsx index 2fc0677a..25fd477b 100644 --- a/src/lib/getUnloadMessage.spec.tsx +++ b/src/lib/getUnloadMessage.spec.tsx @@ -1,9 +1,10 @@ import { getUnloadMessage } from './getUnloadMessage'; import React from 'react'; import { useUpdateTask } from './api/useUpdateTask'; -import { renderWithQueryProvider, resolveWithDelay } from './test/helpers'; +import { renderWithQueryProvider } from './test/helpers'; import { vi, expect, it, describe } from 'vitest'; import { updateTask } from './api'; +import loadControlledPromise from './test/loadControlledPromise'; vi.mock('./api/updateTask'); @@ -15,12 +16,12 @@ describe('getUnloadMessage', () => { }); it('returns message if pending task toggle', () => { - resolveWithDelay(vi.mocked(updateTask), 200); + const { reject } = loadControlledPromise(updateTask); const Component = () => { const updateTask = useUpdateTask(); - updateTask(-1, { complete: true }); + updateTask('-1', { complete: true }); return