Skip to content

Commit

Permalink
pass current answers hash to filter (#533)
Browse files Browse the repository at this point in the history
resolve #428
  • Loading branch information
imyelo authored and SBoudrias committed May 17, 2017
1 parent f99b398 commit da4eceb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/prompts/base.js
Expand Up @@ -91,7 +91,7 @@ Prompt.prototype.handleSubmitEvents = function (submit) {
var validate = runAsync(this.opt.validate);
var filter = runAsync(this.opt.filter);
var validation = submit.flatMap(function (value) {
return filter(value).then(function (filteredValue) {
return filter(value, self.answers).then(function (filteredValue) {
return validate(filteredValue, self.answers).then(function (isValid) {
return {isValid: isValid, value: filteredValue};
}, function (err) {
Expand Down
26 changes: 26 additions & 0 deletions test/specs/api.js
Expand Up @@ -132,6 +132,32 @@ var tests = {
this.rl.emit('line');
return promise;
});

it('should pass previous answers to the prompt filter function', function () {
var prompt = inquirer.createPromptModule();
var questions = [{
type: 'confirm',
name: 'q1',
message: 'message'
}, {
type: 'confirm',
name: 'q2',
message: 'message',
filter: function (input, answers) {
expect(answers.q1).to.be.true;
return input;
},
default: false
}];

var promise = prompt(questions);
autosubmit(promise.ui);

return promise.then(function (answers) {
expect(answers.q1).to.be.true;
expect(answers.q2).to.be.false;
});
});
});
},

Expand Down

0 comments on commit da4eceb

Please sign in to comment.