File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,12 @@ class PromptUI extends Base {
32
32
33
33
// Make sure questions is an array.
34
34
if ( _ . isPlainObject ( questions ) ) {
35
- questions = [ questions ] ;
35
+ // It's either an object of questions or a single question
36
+ questions = Object . values ( questions ) . every (
37
+ ( v ) => _ . isPlainObject ( v ) && v . name === undefined
38
+ )
39
+ ? Object . entries ( questions ) . map ( ( [ name , question ] ) => ( { name, ...question } ) )
40
+ : [ questions ] ;
36
41
}
37
42
38
43
// Create an observable, unless we received one as parameter.
Original file line number Diff line number Diff line change @@ -97,6 +97,26 @@ describe('inquirer.prompt', () => {
97
97
} ) ;
98
98
} ) ;
99
99
100
+ it ( 'should take a prompts nested object and return answers' , async function ( ) {
101
+ var prompts = {
102
+ q1 : {
103
+ type : 'confirm' ,
104
+ message : 'message' ,
105
+ } ,
106
+ q2 : {
107
+ type : 'input' ,
108
+ message : 'message' ,
109
+ default : 'Foo' ,
110
+ } ,
111
+ } ;
112
+
113
+ var promise = this . prompt ( prompts ) ;
114
+ autosubmit ( promise . ui ) ;
115
+ const { q1, q2 } = await promise ;
116
+ expect ( q1 ) . to . equal ( true ) ;
117
+ expect ( q2 ) . to . equal ( 'Foo' ) ;
118
+ } ) ;
119
+
100
120
it ( 'should take a prompts array with nested names' , function ( ) {
101
121
const prompts = [
102
122
{
You can’t perform that action at this time.
0 commit comments