I am creating a cli app using oclif . The user executes a command, and the cli asks him if wants to continue (yes/no answer).
I trying to test the command that uses the cli-ux prompt . I want to simulate the user interaction to enter the 'yes' word.
How can I do that? I tried this:
describe('mycommand', () => {
test
.stdout()
.command(['mycommand', 'action'])
.stdin('y')
.it('it shoud do someting', ctx => {});
});
Related with Oclif prompt testing I could find a solution.
Be careful how you ask the user because you can use cli.prompt
or cli.confirm
. In my case, I use cli.confirm
so a possible test could be:
describe('it should clean items in done list', () => {
test
.stub(cli, 'confirm', () => async () => 'Y')
.stdout()
.command(['clean', 'done'])
.it('it shoud clean items in done list', ctx => {
// test
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.