Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion docs/ecosystem-user-event.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ set `skipPointerEventsCheck` to `true`:
userEvent.click(elem, undefined, {skipPointerEventsCheck: true})
```

The `skipPointerEventsCheck` option can be passed to any pointer related API including:
The `skipPointerEventsCheck` option can be passed to any pointer related API
including:

- [dblClick](#dblclickelement-eventinit-options)
- [hover](#hoverelement-options)
- [unhover](#unhoverelement-options)
Expand Down Expand Up @@ -204,6 +206,29 @@ test('delete characters within the selectedRange', () => {
userEvent.type(input, '{backspace}good')

expect(input).toHaveValue('This is a good example')
```

By default, `type` appends to the existing text. To prepend text, reset the
element's selection range and provide the `initialSelectionStart` and
`initialSelectionEnd` options:

```jsx
import React from 'react'
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'

test('prepend text', () => {
render(<input defaultValue="World!"/>)
const element = screen.getByRole('textbox')

// Prepend text
element.setSelectionRange(0, 0)
userEvent.type(element, 'Hello, ', {
initialSelectionStart: 0,
initialSelectionEnd: 0,
})

expect(element).toHaveValue('Hello, World!')
})
```

Expand Down