Skip to content

Commit

Permalink
fix: remove redundant checks in test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherPHolder committed Feb 27, 2024
1 parent 73ac637 commit 88aab18
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions packages/cli/src/lib/core/prompt/confirm-to-process.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,53 @@ describe('confirmToProcess', () => {
const mockPrompt = 'Confirm should process?';
const promptParamSpy = jest.spyOn(prompt, 'promptParam');
const mockProcess = jest.fn();
const mockPrecondition = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
})

it('should check if precondition is met', async () => {
mockPrecondition.mockResolvedValue(false);
it('should check if precondition is met if one is given', async () => {
const mockPrecondition = jest.fn();
await confirmToProcess({
prompt: mockPrompt,
process: mockProcess,
precondition: mockPrecondition,
})(CONTEXT);
})(EMPTY_CONTEXT);
expect(mockPrecondition).toHaveBeenCalled();
});

it('should not prompt if precondition is not met', async () => {
mockPrecondition.mockResolvedValue(false);
await confirmToProcess({
prompt: mockPrompt,
process: mockProcess,
precondition: mockPrecondition,
})(CONTEXT);
expect(mockPrecondition).toHaveBeenCalled();
precondition: () => false,
})(EMPTY_CONTEXT);
expect(promptParamSpy).not.toHaveBeenCalled();
});

it('should prompt if precondition is met', async () => {
mockPrecondition.mockResolvedValue(true);
await confirmToProcess({
prompt: mockPrompt,
process: mockProcess,
precondition: mockPrecondition,
})(CONTEXT);
expect(mockPrecondition).toHaveBeenCalled();
})(EMPTY_CONTEXT);
expect(promptParamSpy).toHaveBeenCalled();
});

it('should not process if prompt is denied', async () => {
mockPrecondition.mockResolvedValue(true);
promptParamSpy.mockResolvedValue(false);
await confirmToProcess({
prompt: mockPrompt,
process: mockProcess,
precondition: mockPrecondition,
})(CONTEXT);
})(EMPTY_CONTEXT);
expect(mockProcess).not.toHaveBeenCalled();
});

it('should process if prompt is accepted', async () => {
mockPrecondition.mockResolvedValue(true);
promptParamSpy.mockResolvedValue(false);
await confirmToProcess({
prompt: mockPrompt,
process: mockProcess,
precondition: mockPrecondition,
})(CONTEXT);
})(EMPTY_CONTEXT);
expect(mockProcess).not.toHaveBeenCalled();
});
})

0 comments on commit 88aab18

Please sign in to comment.