@@ -1647,6 +1647,59 @@ describe('Command', () => {
16471647 argv . rest . should . equal ( 'bar baz' ) ;
16481648 coerceExecutionCount . should . equal ( 1 ) ;
16491649 } ) ;
1650+
1651+ // Addresses: https://github.com/yargs/yargs/issues/2130
1652+ it ( 'should not run or set new properties on argv when related argument is not passed' , ( ) => {
1653+ yargs ( 'cmd1' )
1654+ . command (
1655+ 'cmd1' ,
1656+ 'cmd1 desc' ,
1657+ yargs =>
1658+ yargs
1659+ . option ( 'foo' , { alias : 'f' , type : 'string' } )
1660+ . option ( 'bar' , {
1661+ alias : 'b' ,
1662+ type : 'string' ,
1663+ implies : 'f' ,
1664+ coerce : ( ) => expect . fail ( ) , // Should not be called
1665+ } )
1666+ . fail ( ( ) => {
1667+ expect . fail ( ) ; // Should not fail because of implies
1668+ } ) ,
1669+ argv => {
1670+ // eslint-disable-next-line no-prototype-builtins
1671+ if ( Object . prototype . hasOwnProperty ( argv , 'b' ) ) {
1672+ expect . fail ( ) ; // 'b' was not provided, coerce should not set it
1673+ }
1674+ }
1675+ )
1676+ . strict ( )
1677+ . parse ( ) ;
1678+ } ) ;
1679+
1680+ // Addresses: https://github.com/yargs/yargs/issues/2159
1681+ it ( 'should not add aliases to argv if strip-aliased config is true' , ( ) => {
1682+ yargs ( 'cmd1 -f hello -b world' )
1683+ . parserConfiguration ( { 'strip-aliased' : true } )
1684+ . command (
1685+ 'cmd1' ,
1686+ 'cmd1 desc' ,
1687+ yargs =>
1688+ yargs . option ( 'foo' , { alias : 'f' , type : 'string' } ) . option ( 'bar' , {
1689+ type : 'string' ,
1690+ alias : 'b' ,
1691+ coerce : val => val ,
1692+ } ) ,
1693+ argv => {
1694+ // eslint-disable-next-line no-prototype-builtins
1695+ if ( Object . prototype . hasOwnProperty ( argv , 'b' ) ) {
1696+ expect . fail ( ) ; // 'b' is an alias, it should not be in argv
1697+ }
1698+ }
1699+ )
1700+ . strict ( )
1701+ . parse ( ) ;
1702+ } ) ;
16501703 } ) ;
16511704
16521705 describe ( 'defaults' , ( ) => {
0 commit comments