Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.26 KB

ecosystem-cli-testing-library.mdx

File metadata and controls

48 lines (33 loc) · 1.26 KB
idtitle
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.

close