我正在创建一个cli应用程序使用oclif。用户执行命令,cli询问他是否要继续(是/否回答)。
我尝试测试使用cli-ux prompt的命令。我想要模拟用户交互来输入“yes”这个词。
我该怎么做呢?我试过这个:
describe('mycommand', () => {
test
.stdout()
.command(['mycommand', 'action'])
.stdin('y')
.it('it shoud do someting', ctx => {});
});
发布于 2019-07-30 21:12:38
关于Oclif prompt testing,我可以找到一个解决方案。
请注意询问用户的方式,因为您可以使用cli.prompt
或cli.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
});
});
https://stackoverflow.com/questions/56923964
复制相似问题