react-select-event
A react-select-event
é uma biblioteca acompanhante para
React Testing Library
que fornece métodos auxiliares para interagir com os
elementos de react-select
.
- npm
- Yarn
npm install --save-dev react-select-event
yarn add --dev react-select-event
import React from 'react'
import Select from 'react-select'
import {render} from '@testing-library/react'
import selectEvent from 'react-select-event'
const {getByTestId, getByLabelText} = render(
<form data-testid="form">
<label htmlFor="food">Food</label>
<Select options={OPTIONS} name="food" inputId="food" isMulti />
</form>,
)
expect(getByTestId('form')).toHaveFormValues({food: ''}) // seletor vazio
// selecionar dois valores...
await selectEvent.select(getByLabelText('Food'), ['Strawberry', 'Mango'])
expect(getByTestId('form')).toHaveFormValues({food: ['strawberry', 'mango']})
// ...e adicionar um terceiro
await selectEvent.select(getByLabelText('Food'), 'Chocolate')
expect(getByTestId('form')).toHaveFormValues({
food: ['strawberry', 'mango', 'chocolate'],
})