/
unknown.test.js
26 lines (23 loc) · 1.08 KB
/
unknown.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
const { run } = require('../utils/test-utils');
const { red } = require('colorette');
describe('unknown behaviour', () => {
it('warns the user if an unknown flag is passed in', () => {
const { stderr, exitCode } = run(__dirname, ['--unknown']);
expect(stderr).toBeTruthy();
expect(stderr).toContain(`${red('Unknown argument: --unknown')}`);
expect(exitCode).toBe(2);
});
it('throws error for unknow flag and respect --no-color', () => {
const { stderr, exitCode } = run(__dirname, ['--unknown', '--no-color']);
expect(stderr).toBeTruthy();
expect(stderr).not.toContain(`${red('Unknown argument: --unknown')}`);
expect(stderr).toContain('Unknown argument: --unknown');
expect(exitCode).toBe(2);
});
it('suggests the closest match to an unknown flag', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--entyr', './a.js']);
expect(stderr).toContain('Unknown argument: --entyr');
expect(stdout).toContain('Did you mean --entry?');
expect(exitCode).toBe(2);
});
});