Skip to content

Commit 6dbfa5a

Browse files
authored
fix: format docs script (#702)
1 parent 587a3c5 commit 6dbfa5a

26 files changed

+191
-162
lines changed

docs/dom-testing-library/api-async.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ el.parentElement.removeChild(el)
106106
or an empty array:
107107

108108
```javascript
109-
waitForElementToBeRemoved(null).catch(err => console.log(err))
110-
waitForElementToBeRemoved(queryByText(/not here/i)).catch(err =>
109+
waitForElementToBeRemoved(null).catch((err) => console.log(err))
110+
waitForElementToBeRemoved(queryByText(/not here/i)).catch((err) =>
111111
console.log(err)
112112
)
113-
waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err =>
113+
waitForElementToBeRemoved(queryAllByText(/not here/i)).catch((err) =>
114114
console.log(err)
115115
)
116-
waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err =>
116+
waitForElementToBeRemoved(() => getByText(/not here/i)).catch((err) =>
117117
console.log(err)
118118
)
119119

@@ -165,7 +165,7 @@ changed:
165165
const container = document.createElement('div')
166166
waitForDomChange({ container })
167167
.then(() => console.log('DOM changed!'))
168-
.catch(err => console.log(`Error you need to deal with: ${err}`))
168+
.catch((err) => console.log(`Error you need to deal with: ${err}`))
169169
container.append(document.createElement('p'))
170170
// if 👆 was the only code affecting the container and it was not run,
171171
// waitForDomChange would throw an error
@@ -179,7 +179,7 @@ container
179179
```javascript
180180
const container = document.createElement('div')
181181
container.setAttribute('data-cool', 'true')
182-
waitForDomChange({ container }).then(mutationsList => {
182+
waitForDomChange({ container }).then((mutationsList) => {
183183
const mutation = mutationsList[0]
184184
console.log(
185185
`was cool: ${mutation.oldValue}\ncurrently cool: ${mutation.target.dataset.cool}`

docs/dom-testing-library/api-configuration.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ id: api-configuration
33
title: Configuration
44
---
55

6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
6+
import Tabs from '@theme/Tabs'
7+
import TabItem from '@theme/TabItem'
88

99
## Configuration
1010

@@ -50,12 +50,13 @@ option.
5050
screen.getByTestId('foo', { suggest: false }) // will not throw a suggestion
5151
```
5252

53-
`testIdAttribute`: The attribute used by [`getByTestId`](api-queries.mdx#bytestid)
54-
and related queries. Defaults to `data-testid`.
53+
`testIdAttribute`: The attribute used by
54+
[`getByTestId`](api-queries.mdx#bytestid) and related queries. Defaults to
55+
`data-testid`.
5556

5657
`getElementError`: A function that returns the error used when
57-
[`getBy*`](api-queries.mdx#getby) or [`getAllBy*`](api-queries.mdx#getallby) fail. Takes
58-
the error message and container object as arguments.
58+
[`getBy*`](api-queries.mdx#getby) or [`getAllBy*`](api-queries.mdx#getallby)
59+
fail. Takes the error message and container object as arguments.
5960

6061
`asyncUtilTimeout`: The global timeout value in milliseconds used by `waitFor`
6162
utilities. Defaults to 1000ms.

docs/dom-testing-library/api-events.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ id: api-events
33
title: Firing Events
44
---
55

6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
6+
import Tabs from '@theme/Tabs'
7+
import TabItem from '@theme/TabItem'
88

99
> Most projects have a few use cases for `fireEvent`, but the majority of the
1010
> time you should probably use
@@ -149,20 +149,20 @@ bound callback.
149149
}>
150150
<TabItem value="react">
151151

152-
```jsx
153-
import { render, screen, fireEvent } from '@testing-library/react'
152+
```jsx
153+
import { render, screen, fireEvent } from '@testing-library/react'
154154

155-
const Button = ({ onClick, children }) => (
156-
<button onClick={onClick}>{children}</button>
157-
)
155+
const Button = ({ onClick, children }) => (
156+
<button onClick={onClick}>{children}</button>
157+
)
158158

159-
test('calls onClick prop when clicked', () => {
160-
const handleClick = jest.fn()
161-
render(<Button onClick={handleClick}>Click Me</Button>)
162-
fireEvent.click(screen.getByText(/click me/i))
163-
expect(handleClick).toHaveBeenCalledTimes(1)
164-
})
165-
```
159+
test('calls onClick prop when clicked', () => {
160+
const handleClick = jest.fn()
161+
render(<Button onClick={handleClick}>Click Me</Button>)
162+
fireEvent.click(screen.getByText(/click me/i))
163+
expect(handleClick).toHaveBeenCalledTimes(1)
164+
})
165+
```
166166

167167
</TabItem>
168168
</Tabs>

docs/dom-testing-library/api-helpers.mdx

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ id: api-helpers
33
title: Helpers
44
---
55

6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
6+
import Tabs from '@theme/Tabs'
7+
import TabItem from '@theme/TabItem'
88

99
## Custom Queries
1010

@@ -68,8 +68,7 @@ module.exports = {
6868
The `buildQueries` helper allows you to create custom queries with all standard
6969
[variants](api-queries.mdx) of queries in testing-library.
7070

71-
See the
72-
[Add custom queries](react-testing-library/setup.mdx#add-custom-queries)
71+
See the [Add custom queries](react-testing-library/setup.mdx#add-custom-queries)
7372
section of the custom render guide for example usage.
7473

7574
### Using other assertion libraries
@@ -138,32 +137,32 @@ could do:
138137
}>
139138
<TabItem value="native">
140139

141-
```js
142-
import { within } from '@testing-library/dom'
140+
```js
141+
import { within } from '@testing-library/dom'
143142

144-
const { getByText } = within(document.getElementById('messages'))
145-
const helloMessage = getByText('hello')
146-
```
143+
const { getByText } = within(document.getElementById('messages'))
144+
const helloMessage = getByText('hello')
145+
```
147146

148147
</TabItem>
149148
<TabItem value="react">
150149

151-
```jsx
152-
import { render, within } from '@testing-library/react'
150+
```jsx
151+
import { render, within } from '@testing-library/react'
153152

154-
const { getByLabelText } = render(<MyComponent />)
155-
const signinModal = getByLabelText('Sign In')
156-
within(signinModal).getByPlaceholderText('Username')
157-
```
153+
const { getByLabelText } = render(<MyComponent />)
154+
const signinModal = getByLabelText('Sign In')
155+
within(signinModal).getByPlaceholderText('Username')
156+
```
158157

159158
</TabItem>
160159
<TabItem value="cypress">
161160

162-
```js
163-
cy.get('form').within(() => {
164-
cy.findByText('Button Text').should('be.disabled')
165-
})
166-
```
161+
```js
162+
cy.get('form').within(() => {
163+
cy.findByText('Button Text').should('be.disabled')
164+
})
165+
```
167166

168167
</TabItem>
169168
</Tabs>

docs/dom-testing-library/api-queries.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ id: api-queries
33
title: Queries
44
---
55

6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
6+
import Tabs from '@theme/Tabs'
7+
import TabItem from '@theme/TabItem'
88

99
## Variants
1010

@@ -1006,7 +1006,7 @@ To override normalization to remove some Unicode characters whilst keeping some
10061006

10071007
```javascript
10081008
screen.getByText('text', {
1009-
normalizer: str =>
1009+
normalizer: (str) =>
10101010
getDefaultNormalizer({ trim: false })(str).replace(/[\u200E-\u200F]*/g, ''),
10111011
})
10121012
```

docs/dom-testing-library/cheatsheet.mdx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,29 @@ See [Which query should I use?](guide-which-query.mdx)
7777

7878
## Async
7979

80-
See [Async API](dom-testing-library/api-async.mdx). Remember to `await` or `.then()`
81-
the result of async functions in your tests!
80+
See [Async API](dom-testing-library/api-async.mdx). Remember to `await` or
81+
`.then()` the result of async functions in your tests!
8282

83-
- **waitFor** (Promise) retry the function within until it stops throwing or times
84-
out
83+
- **waitFor** (Promise) retry the function within until it stops throwing or
84+
times out
8585
- **waitForElementToBeRemoved** (Promise) retry the function until it no longer
8686
returns a DOM node
8787

8888
> **Deprecated since v7.0.0:**
89-
> - **wait** (Promise) retry the function within until it stops throwing or times
90-
> - **waitForElement** (Promise) retry the function until it returns an element or
91-
> an array of elements
92-
> - `findBy` and `findAllBy` queries are async and retry until either a timeout
93-
> or if the query returns successfully; they wrap `waitForElement`
94-
> - **waitForDomChange** (Promise) retry the function each time the DOM is changed
89+
>
90+
> - **wait** (Promise) retry the function within until it stops throwing or
91+
> times
92+
> - **waitForElement** (Promise) retry the function until it returns an element
93+
> or an array of elements
94+
> - `findBy` and `findAllBy` queries are async and retry until either a timeout
95+
> or if the query returns successfully; they wrap `waitForElement`
96+
> - **waitForDomChange** (Promise) retry the function each time the DOM is
97+
> changed
9598
9699
## Events
97100

98-
See [Considerations for fireEvent](guide-events.mdx), [Events API](api-events.mdx)
101+
See [Considerations for fireEvent](guide-events.mdx),
102+
[Events API](api-events.mdx)
99103

100104
- **fireEvent** trigger DOM event: `fireEvent(node, event)`
101105
- **fireEvent.\*** helpers for default event types

docs/dom-testing-library/faq.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ As you write your tests, keep in mind:
2727

2828
<details>
2929

30-
<summary>What if my app is localized and I don't have access to the text in test?</summary>
30+
<summary>
31+
What if my app is localized and I don't have access to the text in test?
32+
</summary>
3133

3234
This is fairly common. Our first bit of advice is to try to get the default text
3335
used in your tests. That will make everything much easier (more than just using
@@ -38,7 +40,10 @@ with `data-testid`s (which is not bad anyway).
3840

3941
<details>
4042

41-
<summary>I really don't like data-testids, but none of the other queries make sense. Do I have to use a data-testid?</summary>
43+
<summary>
44+
I really don't like data-testids, but none of the other queries make sense. Do
45+
I have to use a data-testid?
46+
</summary>
4247

4348
Definitely not. That said, a common reason people don't like the `data-testid`
4449
attribute is they're concerned about shipping that to production. I'd suggest
@@ -67,7 +72,10 @@ const rootElement = container.firstChild
6772

6873
<details>
6974

70-
<summary>What if I’m iterating over a list of items that I want to put the data-testid="item" attribute on. How do I distinguish them from each other?</summary>
75+
<summary>
76+
What if I’m iterating over a list of items that I want to put the
77+
data-testid="item" attribute on. How do I distinguish them from each other?
78+
</summary>
7179

7280
You can make your selector just choose the one you want by including :nth-child
7381
in the selector.
@@ -109,7 +117,6 @@ library for more info.
109117

110118
<!-- Links: -->
111119

112-
113120
<!-- prettier-ignore-start -->
114121

115122
[guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106

docs/example-codesandbox.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ You can find runnable examples for many common use cases on Codesandbox.
88

99
[![Open react-testing-library-examples](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/kentcdodds/react-testing-library-examples/tree/master/)
1010

11-
<iframe src="https://codesandbox.io/embed/github/kentcdodds/react-testing-library-examples/tree/master/?expanddevtools=1&fontsize=13&hidenavigation=1&initialpath=%2F__tests__%2Fasync.js&module=%2Fsrc%2F__tests__%2Fasync.js&moduleview=1&previewwindow=tests&view=editor" style={{width: '100%', height:500, border:0, borderRadius: 4, overflow:'hidden'}} sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
11+
<iframe
12+
src="https://codesandbox.io/embed/github/kentcdodds/react-testing-library-examples/tree/master/?expanddevtools=1&fontsize=13&hidenavigation=1&initialpath=%2F__tests__%2Fasync.js&module=%2Fsrc%2F__tests__%2Fasync.js&moduleview=1&previewwindow=tests&view=editor"
13+
style={{
14+
width: '100%',
15+
height: 500,
16+
border: 0,
17+
borderRadius: 4,
18+
overflow: 'hidden',
19+
}}
20+
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
21+
></iframe>
1222

1323
## Playground
1424

docs/example-drag.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ function getElementClientCenter(element) {
5757
}
5858
}
5959

60-
const getCoords = charlie =>
60+
const getCoords = (charlie) =>
6161
isElement(charlie) ? getElementClientCenter(charlie) : charlie
6262

63-
const sleep = ms =>
64-
new Promise(resolve => {
63+
const sleep = (ms) =>
64+
new Promise((resolve) => {
6565
setTimeout(resolve, ms)
6666
})
6767

docs/example-external.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ sidebar_label: External Examples
2020
Tolinski
2121

2222
<a href="https://youtu.be/JKOwJUM4_RM">
23-
<img width="200px" alt="what is react testing library" src='https://img.youtube.com/vi/JKOwJUM4_RM/0.jpg' style={{marginLeft: 36}} />
23+
<img
24+
width="200px"
25+
alt="what is react testing library"
26+
src="https://img.youtube.com/vi/JKOwJUM4_RM/0.jpg"
27+
style={{ marginLeft: 36 }}
28+
/>
2429
</a>

docs/example-input-event.mdx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,24 @@ sidebar_label: Input Event
1111
> [`user-event`](ecosystem-user-event.mdx)
1212
1313
```jsx
14-
import React, {useState} from 'react'
14+
import React, { useState } from 'react'
1515
import { render, fireEvent } from '@testing-library/react'
1616

1717
function CostInput() {
1818
const [value, setValue] = useState('')
1919

20-
removeDollarSign = value => (value[0] === '$' ? value.slice(1) : value)
21-
getReturnValue = value => (value === '' ? '' : `$${value}`)
22-
23-
handleChange = ev => {
20+
removeDollarSign = (value) => (value[0] === '$' ? value.slice(1) : value)
21+
getReturnValue = (value) => (value === '' ? '' : `$${value}`)
22+
23+
handleChange = (ev) => {
2424
ev.preventDefault()
2525
const inputtedValue = ev.currentTarget.value
2626
const noDollarSign = removeDollarSign(inputtedValue)
2727
if (isNaN(noDollarSign)) return
2828
setValue(getReturnValue(noDollarSign))
2929
}
3030

31-
return (
32-
<input
33-
value={value}
34-
aria-label="cost-input"
35-
onChange={handleChange}
36-
/>
37-
)
31+
return <input value={value} aria-label="cost-input" onChange={handleChange} />
3832
}
3933

4034
const setup = () => {

docs/example-react-context.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test('NameProvider composes full name from first, last', () => {
5353
}
5454
customRender(
5555
<NameContext.Consumer>
56-
{value => <span>Received: {value}</span>}
56+
{(value) => <span>Received: {value}</span>}
5757
</NameContext.Consumer>,
5858
{ providerProps }
5959
)

docs/example-react-modal.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Modal = ({ onClose, children }) => {
2323

2424
return ReactDOM.createPortal(
2525
<div onClick={onClose}>
26-
<div onClick={e => e.stopPropagation()}>
26+
<div onClick={(e) => e.stopPropagation()}>
2727
{children}
2828
<hr />
2929
<button onClick={onClose}>Close</button>

0 commit comments

Comments
 (0)