Skip to content

Instantly share code, notes, and snippets.

@matteodepalo
Last active April 12, 2023 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteodepalo/4dbcc035698fe401031b6561dba97be3 to your computer and use it in GitHub Desktop.
Save matteodepalo/4dbcc035698fe401031b6561dba97be3 to your computer and use it in GitHub Desktop.
Code example 2
const ARROW_DOWN = '\u001B[B'
const ENTER = '\r'
describe('SelectPrompt', async () => {
test('choose an answer', async () => {
const onEnter = vi.fn()
const items = [
{label: 'first', value: 'first'},
{label: 'second', value: 'second'},
{label: 'third', value: 'third'},
]
const infoTable = {Add: ['new-ext'], Remove: ['integrated-demand-ext', 'order-discount']}
const renderInstance = render(
<SelectPrompt
message="Associate your project with the org Castile Ventures?"
choices={items}
infoTable={infoTable}
onSubmit={onEnter}
/>,
)
await waitForInputsToBeReady()
await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)
await sendInputAndWaitForChange(renderInstance, ENTER)
expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`
"? Associate your project with the org Castile Ventures?
✔ second
"
`)
expect(onEnter).toHaveBeenCalledWith(items[1]!.value)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment