Skip to content

Commit

Permalink
test: false value in when failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGoberling committed Nov 17, 2022
1 parent 7b43d5f commit 5b647da
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/parser/validate.test.ts
Expand Up @@ -790,6 +790,46 @@ describe('validate', () => {
await validate({input, output})
})

it('should fail if the specified flags whose when property resolves to true in exclusive, flag has a false value', async () => {
const input = {
argv: [],
flags: {
cookies: {input: [], name: 'cookies'},
sprinkles: {input: [], name: 'sprinkles'},
dessert: {
input: [],
name: 'dessert',
exclusive: [{name: 'cookies', when: async () => Promise.resolve(true)}],
},
},
args: [],
strict: true,
context: {},
'--': true,
}

const output = {
args: {},
argv: [],
flags: {sprinkles: true, dessert: 'ice-cream', cookies: false},
raw: [
{type: 'flag', flag: 'sprinkles', input: true},
{type: 'flag', flag: 'dessert', input: 'ice-cream'},
{type: 'flag', flag: 'cookies', input: false},
],
metadata: {},
}

try {
// @ts-expect-error
await validate({input, output})
assert.fail('should have thrown')
} catch (error) {
const err = error as CLIError
expect(err.message).to.include('--cookies=false cannot also be provided when using --dessert')
}
})

describe('mixed', () => {
const input = {
argv: [],
Expand Down

0 comments on commit 5b647da

Please sign in to comment.