Skip to content

Commit

Permalink
add tests for group reset and option uniqueness per group
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Jan 9, 2016
1 parent d387a3d commit de5818a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,34 @@ describe('usage tests', function () {
'Missing', 'required', 'argument:', 'y'
])
})

it('resets groups for a command handler, respecting order', function () {
var r = checkUsage(function () {
return yargs(['upload', '-h'])
.command('upload', 'upload something', function (yargs, argv) {
argv = yargs
.option('q', {
type: 'boolean',
group: 'Flags:'
})
.help('h').group('h', 'Global Flags:')
.wrap(null)
.argv
})
.help('h').group('h', 'Global Flags:')
.wrap(null)
.argv
})

r.logs[0].split('\n').should.deep.equal([
'Flags:',
' -q [boolean]',
'',
'Global Flags:',
' -h Show help [boolean]',
''
])
})
})

describe('epilogue', function () {
Expand Down Expand Up @@ -1747,6 +1775,30 @@ describe('usage tests', function () {
''
])
})

it('only displays a duplicated option once per group', function () {
var r = checkUsage(function () {
return yargs(['-h'])
.help('h')
.group(['batman', 'batman'], 'Heroes:')
.group('robin', 'Heroes:')
.option('robin', {
group: 'Heroes:'
})
.wrap(null)
.argv
})

r.logs[0].split('\n').should.deep.equal([
'Heroes:',
' --batman',
' --robin',
'',
'Options:',
' -h Show help [boolean]',
''
])
})
})

describe('cjk', function () {
Expand Down
2 changes: 2 additions & 0 deletions test/yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ describe('yargs dsl tests', function () {
.string('foo')
.choices('foo', ['bar', 'baz'])
.implies('foo', 'snuh')
.group('foo', 'Group:')
.strict()
.exitProcess(false) // defaults to true.
.env('YARGS')
Expand Down Expand Up @@ -242,6 +243,7 @@ describe('yargs dsl tests', function () {
expect(y.getStrict()).to.equal(false)
expect(y.getDemanded()).to.deep.equal({})
expect(y.getCommandHandlers()).to.deep.equal({})
expect(y.getGroups()).to.deep.equal({})
})
})

Expand Down

0 comments on commit de5818a

Please sign in to comment.