@@ -21,11 +21,48 @@ describe('Unit: UI', function () {
21
21
sandbox . restore ( ) ;
22
22
} ) ;
23
23
24
- it ( 'can be created successfully ', function ( ) {
24
+ describe ( 'constructor ', function ( ) {
25
25
const UI = require ( modulePath ) ;
26
- const ui = new UI ( ) ;
27
26
28
- expect ( ui ) . to . be . ok ;
27
+ it ( 'works with defaults' , function ( ) {
28
+ const ui = new UI ( ) ;
29
+ expect ( ui . stdin ) . to . equal ( process . stdin ) ;
30
+ expect ( ui . stdout ) . to . equal ( process . stdout ) ;
31
+ expect ( ui . stderr ) . to . equal ( process . stderr ) ;
32
+ expect ( ui . verbose ) . to . be . false ;
33
+ expect ( ui . allowPrompt ) . to . be . true ;
34
+ } ) ;
35
+
36
+ it ( 'works with custom options' , function ( ) {
37
+ const stdin = { stdin : true } ;
38
+ const stdout = { stdout : true } ;
39
+ const stderr = { stderr : true } ;
40
+
41
+ const ui = new UI ( {
42
+ stdin : stdin ,
43
+ stdout : stdout ,
44
+ stderr : stderr ,
45
+ verbose : true ,
46
+ allowPrompt : false
47
+ } ) ;
48
+
49
+ expect ( ui . stdin ) . to . equal ( stdin ) ;
50
+ expect ( ui . stdout ) . to . equal ( stdout ) ;
51
+ expect ( ui . stderr ) . to . equal ( stderr ) ;
52
+ expect ( ui . verbose ) . to . be . true ;
53
+ expect ( ui . allowPrompt ) . to . be . false ;
54
+ } ) ;
55
+
56
+ it ( 'sets allowPrompt to false if process.stdout is not a TTY' , function ( ) {
57
+ const stdout = { stdout : true , isTTY : false } ;
58
+ const ui = new UI ( {
59
+ allowPrompt : true ,
60
+ stdout : stdout
61
+ } ) ;
62
+
63
+ expect ( ui . stdout ) . to . equal ( stdout ) ;
64
+ expect ( ui . allowPrompt ) . to . be . false ;
65
+ } ) ;
29
66
} ) ;
30
67
31
68
describe ( 'run' , function ( ) {
@@ -171,7 +208,8 @@ describe('Unit: UI', function () {
171
208
const UI = require ( modulePath ) ;
172
209
173
210
it ( 'fails when prompting is disabled' , function ( done ) {
174
- const ui = new UI ( { allowPrompt : false } ) ;
211
+ const ui = new UI ( ) ;
212
+ ui . allowPrompt = false ;
175
213
const noSpinStub = sandbox . stub ( ui , 'noSpin' ) ;
176
214
177
215
try {
@@ -189,7 +227,8 @@ describe('Unit: UI', function () {
189
227
} ) ;
190
228
191
229
it ( 'passes options to prompt method' , function ( ) {
192
- const ui = new UI ( { allowPrompt : true } ) ;
230
+ const ui = new UI ( ) ;
231
+ ui . allowPrompt = true ;
193
232
const noSpinStub = sandbox . stub ( ui , 'noSpin' ) . callsFake ( ( fn ) => fn ( ) ) ;
194
233
const inquirerStub = sandbox . stub ( ui , 'inquirer' ) . resolves ( ) ;
195
234
0 commit comments