@@ -49,6 +49,7 @@ const mockCommander = (() => {
4949} ) ( ) ;
5050
5151// import after mocks set up
52+ const { InvalidArgumentError } = await import ( 'commander' ) ;
5253const {
5354 authAction,
5455 initAction,
@@ -57,6 +58,7 @@ const {
5758 submitAction,
5859 handleError,
5960} = await easyResolve ( easyMocks ) ;
61+ const { intParser } = await import ( '../src/main.js' ) ;
6062
6163describe ( 'main' , ( ) => {
6264 beforeEach ( ( ) => {
@@ -98,3 +100,25 @@ describe('main', () => {
98100 expect ( handleError ) . toHaveBeenCalledWith ( error ) ;
99101 } ) ) ;
100102} ) ;
103+
104+ describe ( 'argParser()' , ( ) => {
105+ test . each ( [ null , undefined , '' , false , true , { } , Promise . resolve ( true ) ] ) (
106+ 'throws if not parsable as int: %s' ,
107+ ( value ) => {
108+ expect ( ( ) => {
109+ intParser ( [ 1 , 2 , 3 ] ) ( value ) ;
110+ } ) . toThrow ( InvalidArgumentError ) ;
111+ }
112+ ) ;
113+
114+ test ( 'throws if value is not a valid choice' , ( ) => {
115+ expect ( ( ) => {
116+ intParser ( [ 1 , 2 , 3 ] ) ( '4' ) ;
117+ } ) . toThrow ( InvalidArgumentError ) ;
118+ } ) ;
119+
120+ test ( 'returns integer if value is a valid choice' , ( ) => {
121+ const result = intParser ( [ 1 , 2 , 3 ] ) ( '1' ) ;
122+ expect ( result ) . toBe ( 1 ) ;
123+ } ) ;
124+ } ) ;
0 commit comments