From d90c59c959505c0d49d549fd4ba18c518ffe81bc Mon Sep 17 00:00:00 2001 From: John Gee Date: Fri, 13 Oct 2023 19:53:37 +1300 Subject: [PATCH] Restore extra sanity check when enabling storeOptionsAsProperties (#2029) --- lib/command.js | 6 +++--- tests/commander.configureCommand.test.js | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/command.js b/lib/command.js index 16c390065..8cca02598 100644 --- a/lib/command.js +++ b/lib/command.js @@ -761,9 +761,9 @@ Expecting one of '${allowedValues.join("', '")}'`); if (this.options.length) { throw new Error('call .storeOptionsAsProperties() before adding options'); } - // if (Object.keys(this._optionValues).length) { - // throw new Error('call .storeOptionsAsProperties() before setting option values'); - // } + if (Object.keys(this._optionValues).length) { + throw new Error('call .storeOptionsAsProperties() before setting option values'); + } this._storeOptionsAsProperties = !!storeAsProperties; return this; } diff --git a/tests/commander.configureCommand.test.js b/tests/commander.configureCommand.test.js index 9c5a72d03..60940ec18 100644 --- a/tests/commander.configureCommand.test.js +++ b/tests/commander.configureCommand.test.js @@ -85,10 +85,10 @@ test('when storeOptionsAsProperties() after adding option then throw', () => { }).toThrow(); }); -// test('when storeOptionsAsProperties() after setting option value then throw', () => { -// const program = new commander.Command(); -// program.setOptionValue('foo', 'bar'); -// expect(() => { -// program.storeOptionsAsProperties(); -// }).toThrow(); -// }); +test('when storeOptionsAsProperties() after setting option value then throw', () => { + const program = new commander.Command(); + program.setOptionValue('foo', 'bar'); + expect(() => { + program.storeOptionsAsProperties(); + }).toThrow(); +});