-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.test.ts
More file actions
42 lines (32 loc) · 1.29 KB
/
cli.test.ts
File metadata and controls
42 lines (32 loc) · 1.29 KB
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
import { KEY_SEQUENCES, setupTests, TestEnvironment } from '@inquirerer/test';
import { Inquirerer, Question } from 'inquirerer';
const beforeEachSetup = setupTests();
describe('Inquirerer', () => {
let environment: TestEnvironment;
beforeEach(() => {
environment = beforeEachSetup();
});
it('prompts user and correctly processes delayed input', async () => {
const { mockInput, mockOutput, writeResults, transformResults, enqueueInputResponse } = environment;
const prompter = new Inquirerer({
input: mockInput,
output: mockOutput,
noTty: false
});
const questions: Question[] = [{
name: 'autocompleteField',
type: 'autocomplete',
options: ['first option', 'firry second option', 'firry third option']
}];
const argv = {};
enqueueInputResponse({ type: 'read', value: 'fir' });
enqueueInputResponse({ type: 'key', value: KEY_SEQUENCES.DOWN_ARROW });
enqueueInputResponse({ type: 'key', value: KEY_SEQUENCES.DOWN_ARROW });
enqueueInputResponse({ type: 'key', value: KEY_SEQUENCES.ENTER });
const result = await prompter.prompt(argv, questions);
expect(argv).toMatchSnapshot();
expect(result).toMatchSnapshot();
expect(writeResults).toMatchSnapshot();
expect(transformResults).toMatchSnapshot();
});
});