Skip to content

Commit 9bf40c1

Browse files
docs: Ecosystem library agnostic (#579)
* docs: make user-event docs library agnostic * docs: make jest-dom library agnostic * docs: update examples
1 parent fd12290 commit 9bf40c1

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

docs/ecosystem-jest-dom.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ id: ecosystem-jest-dom
33
title: jest-dom
44
---
55

6-
[`jest-dom`][gh] is a companion library for `React Testing Library` that
7-
provides custom DOM element matchers for Jest
6+
[`jest-dom`][gh] is a companion library for Testing Library that provides custom
7+
DOM element matchers for Jest
88

99
```
1010
npm install --save-dev @testing-library/jest-dom
@@ -14,11 +14,17 @@ Then follow [usage section][gh-usage] from jest-dom's documentation to add the
1414
matchers to Jest.
1515

1616
```jsx
17-
<span data-testid="not-empty"><span data-testid="empty"></span></span>
18-
<div data-testid="visible">Visible Example</div>
17+
import { screen } from '@testing-library/dom'
1918

20-
expect(screen.queryByTestId('not-empty')).not.toBeEmptyDOMElement()
21-
expect(screen.getByText('Visible Example')).toBeVisible()
19+
test('uses jest-dom', () => {
20+
document.body.innerHTML = `
21+
<span data-testid="not-empty"><span data-testid="empty"></span></span>
22+
<div data-testid="visible">Visible Example</div>
23+
`
24+
25+
expect(screen.queryByTestId('not-empty')).not.toBeEmptyDOMElement()
26+
expect(screen.getByText('Visible Example')).toBeVisible()
27+
})
2228
```
2329

2430
> Note: when using some of these matchers, you may need to make sure you use a

docs/ecosystem-user-event.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ id: ecosystem-user-event
33
title: user-event
44
---
55

6-
[`user-event`][gh] is a companion library for `React Testing Library` that
7-
provides more advanced simulation of browser interactions than the built-in
8-
`fireEvent` method.
6+
[`user-event`][gh] is a companion library for Testing Library that provides more
7+
advanced simulation of browser interactions than the built-in `fireEvent`
8+
method.
99

1010
```
1111
npm install --save-dev @testing-library/user-event
1212
```
1313

1414
```jsx
15-
import React from 'react'
16-
import { render } from '@testing-library/react'
15+
import { screen } from '@testing-library/dom'
1716
import userEvent from '@testing-library/user-event'
1817

19-
test('click', async () => {
20-
const { getByRole } = render(<textarea />)
18+
test('types inside textarea', async () => {
19+
document.body.innerHTML = `<textarea />`
2120

22-
await userEvent.type(getByRole('textbox'), 'Hello, World!')
23-
expect(getByRole('textbox')).toHaveValue('Hello, World!')
21+
await userEvent.type(screen.getByRole('textbox'), 'Hello, World!')
22+
expect(screen.getByRole('textbox')).toHaveValue('Hello, World!')
2423
})
2524
```
2625

0 commit comments

Comments
 (0)