id | title |
---|---|
ecosystem-cli-testing-library | cli-testing-library |
CLI Testing Library
is a companion library to Testing Library
that aims to mimic the API of Testing Library
for testing CLI applications.
npm install --save-dev cli-testing-library
import{resolve}from'path'import{render}from'cli-testing-library'test('Is able to make terminal input and view in-progress stdout',async()=>{const{clear, findByText, queryByText, userEvent}=awaitrender('node',[resolve(__dirname,'./execute-scripts/stdio-inquirer.js'),])constinstance=awaitfindByText('First option')expect(instance).toBeInTheConsole()expect(awaitfindByText('❯ One')).toBeInTheConsole()clear()userEvent('[ArrowDown]')expect(awaitfindByText('❯ Two')).toBeInTheConsole()clear()userEvent.keyboard('[Enter]')expect(awaitfindByText('First option: Two')).toBeInTheConsole()expect(awaitqueryByText('First option: Three')).not.toBeInTheConsole()})
Check out CLI Testing Library's documentation for a full list of its API.