Skip to content

Commit

Permalink
delete expectNever helper
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Aug 24, 2022
1 parent 43a59bd commit c2f4c39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/components/molecules/Task.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Task from './Task';
import React from 'react';
import {
expectNever,
loadNowDate,
renderWithQueryProvider,
resolveWithDelay,
Expand Down Expand Up @@ -230,24 +229,25 @@ describe('Task component', () => {
});

it('enforces minimum stakes', async () => {
vi.mocked(editTask).mockImplementation(() => {
throw new Error('Should not have been called');
});

renderTask({ cents: 500 });

await openEditDialog();

userEvent.type(screen.getByLabelText('Stakes *'), '{backspace}1');
userEvent.click(screen.getByText('Save'));

// This test may not be effective, since if the submission was made,
// the expectation may have happened previous to the request. We can't
// wait for an error message because the minimum is enforced on the
// stakes field, preventing the request from being made in the first
// place. This test used to use `expectNever`, but it's better to
// avoid using that since it requires a `waitFor` to timeout before
// passing, slowing down the test significantly.
expect(editTask).not.toBeCalled();
});

it('enforces maximum due', async () => {
vi.mocked(editTask).mockImplementation(() => {
throw new Error('Should not have been called');
});

renderTask({ due: '2/1/2022, 11:59 PM' });

await openEditDialog();
Expand All @@ -256,7 +256,7 @@ describe('Task component', () => {

userEvent.click(screen.getByText('Save'));

await expectNever(() => expect(editTask).toBeCalled());
expect(editTask).not.toBeCalled();
});

it('shows loading indicator on edit save', async () => {
Expand Down
5 changes: 0 additions & 5 deletions src/lib/test/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,3 @@ export const loadTasksApiData = ({
loadApiResponse(updateTask as Mock);
loadApiResponse(addTask as Mock);
};

// DEPRECATED: results in slow tests
export async function expectNever(callable: () => unknown): Promise<void> {
await expect(() => waitFor(callable)).rejects.toEqual(expect.anything());
}

1 comment on commit c2f4c39

@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.