Skip to content

Commit

Permalink
delete deprecated helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Aug 24, 2022
1 parent c2f4c39 commit 14a4cf2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/components/molecules/Task.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import {
loadNowDate,
renderWithQueryProvider,
resolveWithDelay,
withMutedReactQueryLogger,
} from '../../lib/test/helpers';
import userEvent from '@testing-library/user-event';
Expand All @@ -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');
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('Task component', () => {
});

it('shows loading indicator on edit save', async () => {
resolveWithDelay(mockEditTask);
const { resolve } = loadControlledPromise(editTask);

renderTask();

Expand All @@ -271,6 +271,8 @@ describe('Task component', () => {
userEvent.click(screen.getByText('Save'));

await screen.findByRole('progressbar');

resolve();
});

it('closes edit dialog on save', async () => {
Expand Down
9 changes: 6 additions & 3 deletions src/lib/getUnloadMessage.spec.tsx
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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 <div>Component</div>;
};
Expand All @@ -31,5 +32,7 @@ describe('getUnloadMessage', () => {
'There are changes that may be lost if you continue exiting.';

expect(getUnloadMessage(queryClient)).toEqual(expected);

reject();
});
});
21 changes: 0 additions & 21 deletions src/lib/test/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,6 @@ export function renderWithQueryProvider(
};
}

// DEPRECATED: Use `loadControlledPromise` instead.
export function sleep<Type>({
ms = 50,
value = undefined,
}: { ms?: number; value?: Type } = {}): Promise<Type | undefined> {
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',
Expand Down

1 comment on commit 14a4cf2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.