Skip to content

Commit

Permalink
set prompt value in when and return false (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
yujunlong2000 authored and SBoudrias committed May 14, 2018
1 parent 54cc022 commit ff89798
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ui/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class PromptUI extends Base {
* Once all prompt are over
*/

onCompletion(answers) {
onCompletion() {
this.close();

return answers;
return this.answers;
}

processQuestion(question) {
Expand Down
20 changes: 20 additions & 0 deletions test/specs/inquirer.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,26 @@ describe('inquirer.prompt', function() {
expect(answers.q2).to.equal('foo-bar');
});
});

it('should get the value which set in `when` on returns false', function() {
var prompts = [
{
name: 'q',
message: 'message',
when: function(answers) {
answers.q = 'foo';
return false;
}
}
];

var promise = this.prompt(prompts);
autosubmit(promise.ui);

return promise.then(answers => {
expect(answers.q).to.equal('foo');
});
});
});

describe('#registerPrompt()', function() {
Expand Down

0 comments on commit ff89798

Please sign in to comment.