@@ -34,6 +34,15 @@ test('binds command', () => {
3434 expect ( command . commands . find ( ( o ) => o . name === 'help' ) ) . toBeTruthy ( )
3535} )
3636
37+ test ( 'prints help from command' , ( ) => {
38+ const command = massarg ( opts ) . help ( {
39+ bindCommand : true ,
40+ } )
41+ const log = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
42+ command . parse ( [ 'help' ] )
43+ expect ( log ) . toHaveBeenCalled ( )
44+ } )
45+
3746test ( 'binds option' , ( ) => {
3847 const command = massarg ( opts ) . help ( {
3948 bindOption : true ,
@@ -43,13 +52,35 @@ test('binds option', () => {
4352 expect ( command . options . find ( ( o ) => o . name === 'help' ) ) . toBeTruthy ( )
4453} )
4554
55+ describe ( 'prints help from option' , ( ) => {
56+ test ( 'when no main command' , ( ) => {
57+ const command = massarg ( opts ) . help ( {
58+ bindOption : true ,
59+ } )
60+ const log = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
61+ command . parse ( [ '--help' ] )
62+ expect ( log ) . toHaveBeenCalled ( )
63+ } )
64+
65+ test ( 'when main command' , ( ) => {
66+ const mainCmd = jest . fn ( )
67+ const command2 = massarg ( opts )
68+ . help ( {
69+ bindOption : true ,
70+ } )
71+ . main ( mainCmd )
72+ command2 . parse ( [ '--help' ] )
73+ expect ( mainCmd ) . not . toHaveBeenCalled ( )
74+ } )
75+ } )
76+
4677test ( 'help string' , ( ) => {
4778 const command = massarg ( opts )
4879 expect ( command . helpString ( ) ) . toContain ( `Usage:` )
4980} )
5081
5182test ( 'print help' , ( ) => {
52- const log = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
83+ const log = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
5384 const command = massarg ( opts )
5485 command . printHelp ( )
5586 expect ( log ) . toHaveBeenCalled ( )
0 commit comments