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

Injecting answers/values for prompts #234

Closed
faustbrian opened this issue Dec 9, 2019 · 3 comments
Closed

Injecting answers/values for prompts #234

faustbrian opened this issue Dec 9, 2019 · 3 comments

Comments

@faustbrian
Copy link

faustbrian commented Dec 9, 2019

I am currently dabbling with enquirer and so far it seems solid but how to interact with prompts in tests is quite unclear.

With https://github.com/terkelg/prompts it is possible to inject your response before a prompt is called anywhere. This means that you don't need to have access to the prompt object itself and makes testing anything a breeze. This is important for when you test things like CLI commands where you want to give different answers and act like a user without being able to enter something physically with your keyboard.

All of the enquirer internal tests obviously have access to the prompts directly so you don't need anything like that to test the prompts itself but when you are testing something that uses prompts and you are unable to physically input an answer you'll need either injection or another kind of mechanism to let enquirer know what should be used as a response unless you want to litter your tests with mocks.

The README mentions the following: All prompts are well-tested, and tests are easy to create without having to use brittle, hacky solutions to spy on prompts or "inject" values.. Since there is no need for hacky solutions or injection, how do I tell enquirer what value should be used for a specific prompt?

@enquirer enquirer locked as spam and limited conversation to collaborators Dec 9, 2019
@jonschlinkert jonschlinkert reopened this Dec 9, 2019
@enquirer enquirer unlocked this conversation Dec 9, 2019
@aSapien
Copy link

aSapien commented Jan 15, 2020

Quite a bummer though. I can't run E2E tests because I don't have direct access to the prompt instance.

@jonschlinkert
Copy link
Member

jonschlinkert commented Jan 15, 2020 via email

@enquirer enquirer deleted a comment from aSapien Jan 15, 2020
@enquirer enquirer deleted a comment from faustbrian Jan 15, 2020
@enquirer enquirer deleted a comment from faustbrian Jan 15, 2020
@enquirer enquirer locked as off-topic and limited conversation to collaborators Jan 15, 2020
@enquirer enquirer deleted a comment from faustbrian Jan 15, 2020
@jonschlinkert
Copy link
Member

@faustbrian there are quite literally hundreds of unit tests in Enquirer that do exactly what you're describing. This is described in the readme. I deleted other comments on this thread because of the unnecessary negativity and off-topic discussion.

unless you want to litter your tests with mocks

It's far easier to pass data to Enquirer prompts, no need for mocks. I'm not sure what you're missing, but this is one of the problems we solved in Enquirer. What the prompts library does is no different than passing a global object to all prompts, and that library has very few unit tests comparatively, probably because it's a pain to pass data to prompts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants