[英]How test a user input using cli-ux prompt in oclif?
我正在使用oclif創建一個cli應用程序。 用戶執行命令,然后cli詢問他是否要繼續(是/否)。
我試圖測試使用cli-ux提示符的命令 。 我想模擬用戶交互以輸入“是”字樣。
我怎樣才能做到這一點? 我嘗試了這個:
describe('mycommand', () => {
test
.stdout()
.command(['mycommand', 'action'])
.stdin('y')
.it('it shoud do someting', ctx => {});
});
與Oclif即時測試相關,我可以找到一個解決方案。
請謹慎詢問用戶,因為您可以使用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
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.