-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.test.js
45 lines (36 loc) · 1.13 KB
/
error.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
33
34
35
36
37
38
39
40
41
42
43
44
45
const chalk = require('chalk');
const commander = require('commander');
const path = require('path');
const execSync = require('child_process').execSync;
const packageJson = require('./package.json');
const originalConsoleLog = console.log;
console.log = jest.fn();
const originalConsoleError = console.error;
console.error = jest.fn();
jest.mock('child_process', () => {
const execSync = jest.fn();
return { execSync };
});
jest.mock('chalk', () => {
const red = jest.fn(text => text);
const cyan = jest.fn(text => text);
const green = jest.fn(text => text);
const magenta = jest.fn(text => text);
return {
red,
cyan,
green,
magenta,
};
});
describe('cli shows error', () => {
it('cli runs without arguments', () => {
const originalProcessExit = process.exit;
process.exit = jest.fn();
process.argv[2] = '';
require('./cli');
expect(console.error.mock.calls).toEqual([['In order to create a new project you must give a name as an argument. ', 'Example: create-react-once-app AppName']]);
expect(process.exit.mock.calls).toEqual([[1]]);
process.exit = originalProcessExit;
});
});