Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected responses should be validated #197

Open
stefanpl opened this issue Aug 29, 2019 · 2 comments
Open

Injected responses should be validated #197

stefanpl opened this issue Aug 29, 2019 · 2 comments
Labels

Comments

@stefanpl
Copy link

@stefanpl stefanpl commented Aug 29, 2019

Right now, values provided via the inject method are not passed to the questions' validate functions, but set as a value straight away. This prevents testing of falsy user input.

Minimal example:

  const prompts = require('prompts');
  (async () => {
    prompts.inject(['a', 'abc']);
    const response = await prompts({
      type: 'text',
      name: 'example',
      message: 'Should be longer than 1',
      validate: val => val.length > 1,
    });
    assert.strictEqual(response.name, 'abc');
  })();

This will fail, as the validate function is never called and 'a' is returned as an answer. Bummer.

I really like the possibility to inject values, it makes this project stand out from other alternatives which are not as easily testable. But without the possibility to also test custom validators, this is by far not as useful as it could be.

@terkelg
Copy link
Owner

@terkelg terkelg commented Sep 10, 2019

Good point – we still have to improve the way testing works! Thank you

@DrunkenPoney
Copy link
Contributor

@DrunkenPoney DrunkenPoney commented Nov 7, 2019

Why dont we just use stdin.push('answer') to inject responses? Would it not be much simpler? @terkelg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.