Skip to content

Instantly share code, notes, and snippets.

@chico
Created February 12, 2022 22:01
Show Gist options
  • Save chico/68d4f90069457c6c3f18f540328d5a09 to your computer and use it in GitHub Desktop.
Save chico/68d4f90069457c6c3f18f540328d5a09 to your computer and use it in GitHub Desktop.
5 - Testing with sinon & mock-stdin
import inquirer from 'inquirer'
import sinon from 'sinon'
const stubPrompts = (results) => {
const stub = sinon.stub(inquirer, 'prompt')
for (const [index, result] of results.entries()) {
stub.onCall(index).resolves({ result })
}
return stub
}
...
stubPrompts(['1st answer', '2nd answer'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment