File tree Expand file tree Collapse file tree 2 files changed +20
-15
lines changed Expand file tree Collapse file tree 2 files changed +20
-15
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ id: ecosystem-jest-dom
33title : 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```
1010npm 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
1414matchers 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
Original file line number Diff line number Diff line change @@ -3,24 +3,23 @@ id: ecosystem-user-event
33title : 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```
1111npm 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'
1716import 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
You can’t perform that action at this time.
0 commit comments