-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
124 lines (100 loc) · 2.84 KB
/
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
require('mocha');
var assert = require('assert');
var Checkbox = require('prompt-checkbox');
var Prompt = require('prompt-base');
var answer = require('./');
describe('prompt-answer', function() {
it('should export a function', function() {
assert.equal(typeof Prompt, 'function');
});
it('should intantiate', function() {
var prompt = new Prompt({name: 'foo'});
assert(prompt instanceof Prompt);
});
it('should intantiate without new', function() {
var prompt = Prompt({name: 'foo'});
assert(prompt instanceof Prompt);
});
it('should throw an error when invalid args are passed', function() {
assert.throws(function() {
Prompt();
}, /expected question to be a string or object/);
assert.throws(function() {
new Prompt();
}, /expected question to be a string or object/);
});
it('should accept a number keypress on run', function(cb) {
var prompt = new Checkbox({
name: 'color',
message: 'What colors do you like?',
choices: ['red', 'green', 'blue']
});
answer(prompt, 2);
prompt.run()
.then(function(answer) {
assert.deepEqual(answer, ['green']);
cb();
})
});
it('should accept an array of number keypresses on run', function(cb) {
var prompt = new Checkbox({
name: 'color',
message: 'What colors do you like?',
choices: ['red', 'green', 'blue']
});
answer(prompt, [1, 2]);
prompt.run()
.then(function(answer) {
assert.deepEqual(answer, ['red', 'green']);
cb();
})
});
it('should accept a number keypress on ask', function(cb) {
var prompt = new Checkbox({
name: 'color',
message: 'What colors do you like?',
choices: ['red', 'green', 'blue']
});
answer(prompt, 2);
prompt.ask(function(answer) {
assert.deepEqual(answer, ['green']);
cb();
});
});
it('should accept an array of number keypresses on ask', function(cb) {
var prompt = new Checkbox({
name: 'color',
message: 'What colors do you like?',
choices: ['red', 'green', 'blue']
});
answer(prompt, [1, 2]);
prompt.ask(function(answer) {
assert.deepEqual(answer, ['red', 'green']);
cb();
});
});
it('should return an answers object on run', function(cb) {
var prompt = new Prompt({
name: 'color',
message: 'What is your favorite color?'
});
answer(prompt, 'blue');
prompt.run()
.then(function(answer) {
assert.deepEqual(answer, 'blue');
cb();
})
});
it('should return an answers object on ask', function(cb) {
var prompt = new Prompt({
name: 'color',
message: 'What is your favorite color?'
});
answer(prompt, 'green');
prompt.ask(function(answer) {
assert.deepEqual(answer, 'green');
cb();
});
});
});