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

Recommended way of testing `validate` outcome? #199

faustbrian opened this issue Sep 6, 2019 · 2 comments


Copy link

commented Sep 6, 2019

I've recently started to write some tests for an application that uses prompts for its CLI but encountered an issue.

Simulating input is easy thanks to the inject method so getting to 100% coverage is fairly easy except for 1 issue, how would you test the validate outcome of prompt items?

For example I have a prompt that expects a value to be a number and when I run the CLI it properly outputs an error when I enter a string but during tests I with inject I can just add any value and the validate gets never triggered.

Is there currently any way to make prompts respect the validation rules specified in validate?


This comment has been minimized.

Copy link

commented Sep 10, 2019

Thank you for the issue – I think this relates to #197. Testing is something that needs improvement for sure.


This comment has been minimized.

Copy link

commented Sep 10, 2019

Thinking if something as simple prompts.inject([], false) would be sufficient. Then internally we would do 2 things based on the second argument.

  1. Treat the argument as skipValidation and pass it around.
  2. If the value is false we do not skip validation, instead we throw an exception if we detect that the value is injected.

@terkelg What do you think about that approach? Would make failing validation easy to test with something like jest as await expect(prompts()).rejects.toThrow().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.