From 14a4cf24bd5be6924a86fbfbf8d5cbbb03916662 Mon Sep 17 00:00:00 2001 From: Nathan Arthur Date: Wed, 24 Aug 2022 14:28:58 -0400 Subject: [PATCH] delete deprecated helpers --- src/components/molecules/Task.spec.tsx | 6 ++++-- src/lib/getUnloadMessage.spec.tsx | 9 ++++++--- src/lib/test/helpers.tsx | 21 --------------------- 3 files changed, 10 insertions(+), 26 deletions(-) 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
Component
; }; @@ -31,5 +32,7 @@ describe('getUnloadMessage', () => { 'There are changes that may be lost if you continue exiting.'; expect(getUnloadMessage(queryClient)).toEqual(expected); + + reject(); }); }); diff --git a/src/lib/test/helpers.tsx b/src/lib/test/helpers.tsx index 3d0d528d..f38826d4 100644 --- a/src/lib/test/helpers.tsx +++ b/src/lib/test/helpers.tsx @@ -139,27 +139,6 @@ export function renderWithQueryProvider( }; } -// DEPRECATED: Use `loadControlledPromise` instead. -export function sleep({ - ms = 50, - value = undefined, -}: { ms?: number; value?: Type } = {}): Promise { - return new Promise((resolve) => - setTimeout(() => { - resolve(value); - }, ms) - ); -} - -// DEPRECATED: Use `loadControlledPromise` instead. -export function resolveWithDelay( - mock: SpyInstance, - ms = 50, - value: unknown = undefined -): void { - mock.mockImplementation(() => sleep({ ms, value })); -} - export function makeTask({ complete = false, due = '5/22/2020, 11:59 PM',