id | title |
---|---|
ecosystem-react-select-event | react-select-event |
react-select-event
is a companion library for React Testing Library
that provides helper methods for interacting with react-select
elements.
npm install --save-dev react-select-event
importReactfrom'react'importSelectfrom'react-select'import{render}from'@testing-library/react'importselectEventfrom'react-select-event'const{getByTestId, getByLabelText}=render(<formdata-testid="form"><labelhtmlFor="food">Food</label><Selectoptions={OPTIONS}name="food"inputId="food"isMulti/></form>,)expect(getByTestId('form')).toHaveFormValues({food: ''})// empty select// select two values...awaitselectEvent.select(getByLabelText('Food'),['Strawberry','Mango'])expect(getByTestId('form')).toHaveFormValues({food: ['strawberry','mango']})// ...and add a third oneawaitselectEvent.select(getByLabelText('Food'),'Chocolate')expect(getByTestId('form')).toHaveFormValues({food: ['strawberry','mango','chocolate'],})