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

Convenient way to select initial values in tests #44

Open
ianwalter opened this issue Mar 4, 2018 · 3 comments
Open

Convenient way to select initial values in tests #44

ianwalter opened this issue Mar 4, 2018 · 3 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@ianwalter
Copy link
Contributor

ianwalter commented Mar 4, 2018

inject is great when, within a test, you want to simulate the user supplying an answer, but what about when you want to simulate them choosing the initial or default value? I can submit a PR if we can decide on how to implement this. My proposal is that if an injected answer is undefined prompts would just use the initial value. e.g.:

prompts.inject({ a: undefined })
@lukeed
Copy link
Collaborator

lukeed commented Mar 4, 2018

I think @terkelg is working a complete testing solution for simulating interaction(s) with all prompt types.

@terkelg
Copy link
Owner

terkelg commented Mar 4, 2018

You're right @ianwalter - we need better tests for sure. As I see it right now there's two aspects to testing: internal and apis for external testing. I'm open for ideas to both. I started writing some utility functions for internal testing the other day - maybe we can merge the two?

Have a look in the tests branch. Came up with a solution where we expose the internal keypress method from the base prompt element and then use tagged template literals to create a tiny "template-like" language: https://github.com/terkelg/prompts/blob/tests/test/textprompt.js#L17

@terkelg terkelg added this to the v0.1.6 milestone Mar 4, 2018
@ianwalter
Copy link
Contributor Author

ianwalter commented Mar 4, 2018

Yea being able to call/emit a keypress function/readline event with ‘\n’ would suffice although it doesnt bypass showing the prompt like inject does which I think might be ideal for testing.

@terkelg terkelg removed this from the v0.1.7 milestone Mar 11, 2018
@terkelg terkelg added the help wanted Extra attention is needed label Aug 27, 2018
@terkelg terkelg added this to the v3.0.0 milestone Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants