Aller au contenu principal

cli-testing-library

[Traduction Bêta Non Officielle]

Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →

CLI Testing Library est une bibliothèque complémentaire à Testing Library qui vise à reproduire l'API de Testing Library pour tester des applications en ligne de commande.

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} = await render('node', [
resolve(__dirname, './execute-scripts/stdio-inquirer.js'),
])

const instance = await findByText('First option')

expect(instance).toBeInTheConsole()

expect(await findByText('❯ One')).toBeInTheConsole()

clear()

userEvent('[ArrowDown]')

expect(await findByText('❯ Two')).toBeInTheConsole()

clear()

userEvent.keyboard('[Enter]')

expect(await findByText('First option: Two')).toBeInTheConsole()
expect(await queryByText('First option: Three')).not.toBeInTheConsole()
})

Consultez la documentation de CLI Testing Library pour obtenir la liste exhaustive de son API.