Skip to content

Commit fbc8fcd

Browse files
committed
Add example
1 parent 332a43f commit fbc8fcd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,51 @@ Testing Library Extension for Chrome DevTools Recorder
4444

4545
\* Only one `navigate` step is allowed per test because `jest-environment-url` must load pages since `jsdom` does not support navigation. Without any `navigate` steps, you'll need to edit your test to manually load the DOM.
4646

47+
## Example
48+
49+
```json
50+
{
51+
"title": "Example",
52+
"steps": [
53+
{
54+
"type": "navigate",
55+
"url": "https://example.com/",
56+
"assertedEvents": [
57+
{
58+
"type": "navigation",
59+
"url": "https://example.com/",
60+
"title": "Example Domain"
61+
}
62+
]
63+
},
64+
{
65+
"type": "waitForElement",
66+
"frame": [],
67+
"selectors": [
68+
["aria/More information..."],
69+
["body > div > p:nth-child(3) > a"]
70+
]
71+
}
72+
]
73+
}
74+
```
75+
76+
```js
77+
/**
78+
* @jest-environment url
79+
* @jest-environment-options { "url": "https://example.com/" }
80+
*/
81+
const { screen, waitFor } = require("@testing-library/dom")
82+
const userEvent = require("@testing-library/user-event")
83+
require("@testing-library/jest-dom")
84+
85+
test("Example", async () => {
86+
expect(location.href).toBe("https://example.com/")
87+
expect(document.title).toBe("Example Domain")
88+
await waitFor(() => screen.getByText("More information..."))
89+
})
90+
```
91+
4792
## Inspiration
4893

4994
- [Puppeteer Replay examples](https://github.com/puppeteer/replay/tree/main/examples)

0 commit comments

Comments
 (0)