-
-
Notifications
You must be signed in to change notification settings - Fork 591
/
scaffold-utils.test.js
executable file
·75 lines (65 loc) · 2.7 KB
/
scaffold-utils.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// eslint-disable-next-line node/no-missing-require
const { Confirm, List, InputValidate, Input } = require('../../packages/generators/src/utils/scaffold-utils');
describe('utils', () => {
let mockSelf;
beforeEach(() => {
mockSelf = {
prompt: (arg) => {
return arg[0];
},
};
});
describe('Inquirer', () => {
it('should emulate a prompt for List', () => {
expect(List(mockSelf, 'entry', 'does it work?', ['Yes', 'Maybe'], 'Yes')).toEqual({
choices: ['Yes', 'Maybe'],
type: 'list',
name: 'entry',
message: 'does it work?',
default: 'Yes',
});
});
it('should make default value for a List', () => {
expect(List(mockSelf, 'entry', 'does it work?', ['Yes', 'Maybe'], 'Yes', true)).toEqual({
entry: 'Yes',
});
});
it('should emulate a prompt for list input', () => {
expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'openJSF')).toEqual({
type: 'input',
name: 'plugins',
message: 'what is your plugin?',
default: 'openJSF',
});
});
it('should return a default Input object value', () => {
expect(Input(mockSelf, 'plugins', 'what is your plugin?', 'my-plugin', true)).toEqual({
plugins: 'my-plugin',
});
});
it('should emulate a prompt for confirm', () => {
expect(Confirm(mockSelf, 'context', 'what is your context?')).toEqual({
name: 'context',
default: true,
message: 'what is your context?',
type: 'confirm',
});
});
it('should make a Confirm object with yes as default', () => {
expect(Confirm(mockSelf, 'context', 'what is your context?', true, true)).toEqual({
context: true,
});
});
it('should make an Input object with validation', () => {
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true)).toMatchSnapshot();
});
it('should make an Input object with validation and default value', () => {
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin')).toMatchSnapshot();
});
it('should return a default Input object with validation and default value', () => {
expect(InputValidate(mockSelf, 'plugins', 'what is your plugin?', () => true, 'my-plugin', true)).toEqual({
plugins: 'my-plugin',
});
});
});
});