Skip to content

Commit

Permalink
Fix function context at prompt (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhallett authored Jan 29, 2021
1 parent 337dddf commit cd1b557
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class Generator extends EventEmitter {

const storageForQuestion = {};

const getAnswerFromStorage = function(question) {
const getAnswerFromStorage = question => {
let questionStorage = question.storage || storage;
questionStorage =
typeof questionStorage === 'string' ? this[questionStorage] : questionStorage;
Expand Down
11 changes: 11 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,17 @@ describe('Base', () => {
});
});

it('saves answers to config when specified as a property name', function() {
return this.dummy
.prompt([{ ...input1Prompt, storage: 'config' }, input2Prompt])
.then(answers => {
assert.equal(answers.prompt1, 'prompt1NewValue');
assert.equal(answers.prompt2, 'prompt2NewValue');
assert.equal(this.dummy.config.get('prompt1'), 'prompt1NewValue');
assert.equal(this.dummy.config.get('prompt2'), 'prompt2Value');
});
});

it('saves answers to specific storage', function() {
return this.dummy
.prompt([{ ...input1Prompt, storage: this.dummy.config }, input2Prompt])
Expand Down

0 comments on commit cd1b557

Please sign in to comment.