diff --git a/README.md b/README.md index a25eca775..68c25e6be 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ default must the choice `index` in the array) #### Expand - `{type: 'expand'}` Take `type`, `name`, `message`, `choices`[, `default`] properties. (Note that -default must be the choice `index` in the array) +default must be the choice `index` in the array. If `default` key not provided, then `help` will be used as default choice) Note that the `choices` object will take an extra parameter called `key` for the `expand` prompt. This parameter must be a single (lowercased) character. The `h` option is added by the prompt and shouldn't be defined by the user. diff --git a/lib/prompts/expand.js b/lib/prompts/expand.js index bacce48ce..336d98c5a 100644 --- a/lib/prompts/expand.js +++ b/lib/prompts/expand.js @@ -222,7 +222,7 @@ Prompt.prototype.validateChoices = function (choices) { * @return {String} The rendered choices key string */ Prompt.prototype.generateChoicesString = function (choices, defaultIndex) { - var defIndex = 0; + var defIndex = choices.realLength - 1; if (_.isNumber(defaultIndex) && this.opt.choices.getChoice(defaultIndex)) { defIndex = defaultIndex; } diff --git a/test/specs/prompts/expand.js b/test/specs/prompts/expand.js index c34fc5c8b..5c0f9f45c 100644 --- a/test/specs/prompts/expand.js +++ b/test/specs/prompts/expand.js @@ -44,14 +44,6 @@ describe('`expand` prompt', function () { expect(mkPrompt).to.throw(/Reserved key error/); }); - it('should take the first choice by default', function (done) { - this.expand.run().then(function (answer) { - expect(answer).to.equal('acab'); - done(); - }); - this.rl.emit('line'); - }); - it('should allow false as a value', function () { var promise = this.expand.run(); @@ -133,6 +125,14 @@ describe('`expand` prompt', function () { expect(this.rl.output.__raw__).to.contain('(aBcdh)'); }); + it('should display and capitalize the default choice H (Help) `key` if none provided', function () { + delete this.fixture.default; + this.expand = new Expand(this.fixture, this.rl); + this.expand.run(); + + expect(this.rl.output.__raw__).to.contain('(abcdH)'); + }); + it('should \'autocomplete\' the user input', function (done) { this.expand = new Expand(this.fixture, this.rl); this.expand.run();