簡體   English   中英

如何在oclif中使用cli-ux提示測試用戶輸入?

[英]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.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
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM