Skip to content

Commit

Permalink
fix: 'undefined' should be taken to mean no argument was provided (#1015
Browse files Browse the repository at this point in the history
)
  • Loading branch information
edmBernard authored and bcoe committed Dec 18, 2017
1 parent a70b285 commit c679e90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function validation (yargs, usage, y18n) {
// make sure that any args that require an
// value (--foo=bar), have a value.
self.missingArgumentValue = function missingArgumentValue (argv) {
const defaultValues = [true, false, '']
const defaultValues = [true, false, '', undefined]
const options = yargs.getOptions()

if (options.requiresArg.length > 0) {
Expand Down
40 changes: 40 additions & 0 deletions test/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,46 @@ describe('validation tests', () => {
.argv
})

it('fails when a required argument of type number is missing', (done) => {
yargs('-w')
.option('w', {type: 'number', requiresArg: true})
.fail((msg) => {
msg.should.equal('Missing argument value: w')
return done()
})
.argv
})

it('fails when a required argument of type string is missing', (done) => {
yargs('-w')
.option('w', {type: 'string', requiresArg: true})
.fail((msg) => {
msg.should.equal('Missing argument value: w')
return done()
})
.argv
})

it('fails when a required argument of type boolean is missing', (done) => {
yargs('-w')
.option('w', {type: 'boolean', requiresArg: true})
.fail((msg) => {
msg.should.equal('Missing argument value: w')
return done()
})
.argv
})

it('fails when a required argument of type array is missing', (done) => {
yargs('-w')
.option('w', {type: 'array', requiresArg: true})
.fail((msg) => {
msg.should.equal('Missing argument value: w')
return done()
})
.argv
})

it('fails when required arguments are present, but a command is missing', (done) => {
yargs('-w 10 -m wombat')
.demand(1, ['w', 'm'])
Expand Down

0 comments on commit c679e90

Please sign in to comment.