Skip to content

Commit 19ee5de

Browse files
authored
docs: fix the user-event example (#1103)
Resolves: issue #912
1 parent 653801d commit 19ee5de

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/ecosystem-user-event.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,21 @@ method.
615615
Usage example:
616616
617617
```jsx
618-
import React from 'react'
618+
import React, { useState } from 'react'
619619
import {render, screen} from '@testing-library/react'
620620
import userEvent, {specialChars} from '@testing-library/user-event'
621621

622+
const InputElement = () => {
623+
const [currentValue, setCurrentValue] = useState('This is a bad example');
624+
return <div>
625+
<label htmlFor='my-input'>Example:</label>
626+
<input id='my-input' type='text' value={currentValue} onChange={(e) => setCurrentValue(e.target.value)} />
627+
</div>;
628+
}
629+
622630
test('delete characters within the selectedRange', () => {
623631
render(
624-
<div>
625-
<label htmlFor="my-input">Example:</label>
626-
<input id="my-input" type="text" value="This is a bad example" />
627-
</div>,
632+
<InputElement/>,
628633
)
629634
const input = screen.getByLabelText(/example/i)
630635
input.setSelectionRange(10, 13)

0 commit comments

Comments
 (0)