File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -87,5 +87,52 @@ suite('utils', () => {
8787 example5 : 'example5 default'
8888 } )
8989 } )
90+
91+ test ( 'always calls prompt assertions even if when false' , async ( ) => {
92+ let called = 0
93+ function calledAssert ( p ) {
94+ called ++
95+ return true
96+ }
97+ const prompts = [ {
98+ name : 'example' ,
99+ when : true
100+ } , {
101+ name : 'example2' ,
102+ when : false
103+ } , {
104+ name : 'example3' ,
105+ when : ( ) => {
106+ return false
107+ }
108+ } , {
109+ name : 'example4' ,
110+ when : ( ) => {
111+ return true
112+ }
113+ } ]
114+
115+ const pm = utils . test . promptModule ( {
116+ assertCount : 2 ,
117+ prompts : {
118+ example : {
119+ assert : calledAssert
120+ } ,
121+ example2 : {
122+ assert : calledAssert
123+ } ,
124+ example3 : {
125+ assert : calledAssert
126+ } ,
127+ example4 : {
128+ assert : calledAssert
129+ }
130+ }
131+ } ) ( )
132+
133+ await pm ( prompts )
134+
135+ assert . strictEqual ( called , 4 )
136+ } )
90137 } )
91138} )
Original file line number Diff line number Diff line change @@ -76,6 +76,9 @@ function promptModule (opts = {}) {
7676
7777 // If when is false, dont "ask" or set a return
7878 if ( p . when === false ) {
79+ if ( promptOpts . assert ) {
80+ promptOpts . assert ( p )
81+ }
7982 return [ ]
8083 }
8184 if ( typeof p . when === 'function' ) {
@@ -86,6 +89,9 @@ function promptModule (opts = {}) {
8689 whenRet = await whenRet
8790 }
8891 if ( ! whenRet ) {
92+ if ( promptOpts . assert ) {
93+ promptOpts . assert ( p )
94+ }
8995 return [ ]
9096 }
9197 }
You can’t perform that action at this time.
0 commit comments