Skip to content

Commit

Permalink
Improve modal test util types (#3435)
Browse files Browse the repository at this point in the history
  • Loading branch information
develohpanda committed Jun 3, 2021
1 parent fa23003 commit 83f6c20
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/insomnia-app/app/test-utils.ts
@@ -1,16 +1,14 @@
import * as modals from './ui/components/modals';
import type { ErrorModalOptions } from './ui/components/modals/error-modal';
import { PromptModalOptions } from './ui/components/modals/prompt-modal';
import { showAlert, showError, showModal, showPrompt } from './ui/components/modals';

export const getAndClearShowPromptMockArgs = (): PromptModalOptions => {
const mockFn = modals.showPrompt as jest.Mock;
const options = mockFn.mock.calls[0][0] as PromptModalOptions;
export const getAndClearShowPromptMockArgs = () => {
const mockFn = showPrompt as jest.Mock<typeof showPrompt, Parameters<typeof showPrompt>>;
const options = mockFn.mock.calls[0][0];
mockFn.mockClear();
return options;
};

export const getAndClearShowAlertMockArgs = () => {
const mockFn = modals.showAlert as jest.Mock;
const mockFn = showAlert as jest.Mock<typeof showAlert, Parameters<typeof showAlert>>;
const { title, okLabel, addCancel, message, onConfirm } = mockFn.mock.calls[0][0];
mockFn.mockClear();
return {
Expand All @@ -22,15 +20,15 @@ export const getAndClearShowAlertMockArgs = () => {
};
};

export const getAndClearShowErrorMockArgs = (): ErrorModalOptions => {
const mockFn = modals.showError as jest.Mock;
const options: ErrorModalOptions = mockFn.mock.calls[0][0];
export const getAndClearShowErrorMockArgs = () => {
const mockFn = showError as jest.Mock<typeof showError, Parameters<typeof showError>>;
const options = mockFn.mock.calls[0][0];
mockFn.mockClear();
return options;
};

export const getAndClearShowModalMockArgs = () => {
const mockFn = modals.showModal as jest.Mock;
const mockFn = showModal as jest.Mock<typeof showModal, Parameters<typeof showModal>>;
const args = mockFn.mock.calls[0][1];
mockFn.mockClear();
return args;
Expand Down

0 comments on commit 83f6c20

Please sign in to comment.