简体   繁体   English

如何在oclif中使用cli-ux提示测试用户输入?

[英]How test a user input using cli-ux prompt in oclif?

I am creating a cli app using oclif . 我正在使用oclif创建一个cli应用程序。 The user executes a command, and the cli asks him if wants to continue (yes/no answer). 用户执行命令,然后cli询问他是否要继续(是/否)。

I trying to test the command that uses the cli-ux prompt . 我试图测试使用cli-ux提示符的命令 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. Oclif即时测试相关,我可以找到一个解决方案。

Be careful how you ask the user because you can use cli.prompt or cli.confirm . 请谨慎询问用户,因为您可以使用cli.promptcli.confirm In my case, I use cli.confirm so a possible test could be: 就我而言,我使用cli.confirm因此可能的测试可能是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM