-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
resolve-command.test.js
32 lines (25 loc) · 1.09 KB
/
resolve-command.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
jest.setMock('../prompt-installation', jest.fn());
const resolveCommand = require('../resolve-command');
const promptInstallation = require('../prompt-installation');
describe('resolve-command util', () => {
const processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
beforeEach(() => {
processExitSpy.mockClear();
consoleErrorSpy.mockClear();
});
it('should not throw error', async () => {
promptInstallation.mockImplementation(() => {});
await expect(resolveCommand('info')).resolves.not.toThrow();
expect(processExitSpy.mock.calls.length).toBe(0);
expect(consoleErrorSpy.mock.calls.length).toBe(0);
});
it('should throw error and exit with invalid command', async () => {
promptInstallation.mockImplementation(() => {
throw new Error();
});
await resolveCommand('invalid');
expect(processExitSpy).toBeCalledWith(2);
expect(consoleErrorSpy.mock.calls.length).toBe(1);
});
});