2

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 => {});

});
janpio
  • 10,645
  • 16
  • 64
  • 107

1 Answers1

1

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
  });
});