From 5b647da368b3e4ac8a0e1f43580532ce9c56d185 Mon Sep 17 00:00:00 2001 From: Michael Goberling Date: Thu, 17 Nov 2022 13:50:33 -0500 Subject: [PATCH] test: false value in when failure case --- test/parser/validate.test.ts | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/parser/validate.test.ts b/test/parser/validate.test.ts index 9640afc5..61183bec 100644 --- a/test/parser/validate.test.ts +++ b/test/parser/validate.test.ts @@ -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: [],