Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Check inquirer function params
Browse files Browse the repository at this point in the history
Ensure the `answers` object is also passed to the `filter` function.
  • Loading branch information
RobinKnipe committed Oct 8, 2020
1 parent 7e2fb9c commit 30e08d4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/prompt-bypass-mixed.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,45 @@ const prompts = [
{ type:'list', name:'list', message:'listMsg', choices: ['a','B','c'] },
{ type:'input', name:'input', message:'inputMsg' },
{ type:'input', name:'filter', message:'filterMsg', filter: () => 'filter applied' },
{ type:'input', name:'filter2', message:'filterMsg2', filter: () => 't needed' },
{ type:'input', name:'conditional', message:'conditionalMsg', when: () => false }
];

test('verify good bypass input', function (t) {
const [promptsAfterBypassOne, bypassOne] = promptBypass(prompts, ['0'], plop);
t.is(bypassOne.list, 'a');
t.is(promptsAfterBypassOne.length, 4);
t.is(promptsAfterBypassOne.length, 5);
t.is(promptsAfterBypassOne[0].type, undefined);

const [promptsAfterBypassTwo, bypassTwo] = promptBypass(prompts, ['b', 'something'], plop);
t.is(bypassTwo.list, 'B');
t.is(bypassTwo.input, 'something');
t.is(promptsAfterBypassTwo.length, 3);
t.is(promptsAfterBypassTwo.length, 4);

const [promptsAfterBypassThree, bypassThree] = promptBypass(prompts, ['b', 'something', 'something filtered'], plop);
t.is(bypassThree.list, 'B');
t.is(bypassThree.input, 'something');
t.is(bypassThree.filter, 'filter applied');
t.is(promptsAfterBypassThree.length, 2);
t.is(promptsAfterBypassThree.length, 3);

//check correct parameters passed to inquirer function
prompts[3].filter = (input, answers) => {
t.is(input, 'unimportant');
t.is(answers.list, 'B');
t.is(answers.input, 'something');
t.is(answers.filter, 'filter applied');
return answers.list;
};
const [promptsAfterBypassFour, bypassFour] =
promptBypass(prompts, ['b', 'something', 'something filtered', 'unimportant'], plop);
t.is(bypassFour.list, 'B');
t.is(bypassFour.input, 'something');
t.is(bypassFour.filter, 'filter applied');
t.is(bypassFour.filter2, 'B');
t.is(promptsAfterBypassFour.length, 2);
});

test('verify bad bypass input', function (t) {
// can't bypass conditional prompts
t.throws(() => promptBypass(prompts, ['a', 'something', 'something filtered', 'something else'], plop));
t.throws(() => promptBypass(prompts, ['a', 'something', 'something filtered', 'unimportant', 'something else'], plop));
});

0 comments on commit 30e08d4

Please sign in to comment.