如何使用OCLIF中的CLI-UX提示来测试用户输入



我正在使用OCLIF创建一个CLI应用。用户执行命令,CLI问他是否要继续(是/否答案(。

我试图测试使用CLI-UX提示的命令。我想模拟用户交互以输入"是"字。

我该怎么做?我尝试了:

describe('mycommand', () => {
  test
    .stdout()
    .command(['mycommand', 'action'])
    .stdin('y')
    .it('it shoud do someting', ctx => {});
});

与OCLIF提示测试有关的我可以找到解决方案。

请小心您如何询问用户,因为您可以使用cli.promptcli.confirm。就我而言,我使用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
  });
});

最新更新