Skip to content

Commit

Permalink
docs: fix the user-event example (#1103)
Browse files Browse the repository at this point in the history
Resolves: issue #912
  • Loading branch information
polinamochan authored Jul 4, 2022
1 parent 653801d commit 19ee5de
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docs/ecosystem-user-event.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,21 @@ method.
Usage example:
```jsx
import React from 'react'
import React, { useState } from 'react'
import {render, screen} from '@testing-library/react'
import userEvent, {specialChars} from '@testing-library/user-event'

const InputElement = () => {
const [currentValue, setCurrentValue] = useState('This is a bad example');
return <div>
<label htmlFor='my-input'>Example:</label>
<input id='my-input' type='text' value={currentValue} onChange={(e) => setCurrentValue(e.target.value)} />
</div>;
}

test('delete characters within the selectedRange', () => {
render(
<div>
<label htmlFor="my-input">Example:</label>
<input id="my-input" type="text" value="This is a bad example" />
</div>,
<InputElement/>,
)
const input = screen.getByLabelText(/example/i)
input.setSelectionRange(10, 13)
Expand Down

0 comments on commit 19ee5de

Please sign in to comment.