Skip to content

Commit 88e0c07

Browse files
eps1lonSebastian Silbermann
authored and
Sebastian Silbermann
committed
Apply codemod to all
1 parent 10143fa commit 88e0c07

File tree

12 files changed

+123
-123
lines changed

12 files changed

+123
-123
lines changed

src/__tests__/auto-cleanup-skip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ beforeAll(() => {
99

1010
// This one verifies that if RTL_SKIP_AUTO_CLEANUP is set
1111
// then we DON'T auto-wire up the afterEach for folks
12-
test('first', () => {
13-
render(<div>hi</div>)
12+
test('first', async () => {
13+
await render(<div>hi</div>)
1414
})
1515

1616
test('second', () => {

src/__tests__/auto-cleanup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {render} from '../'
44
// This just verifies that by importing RTL in an
55
// environment which supports afterEach (like jest)
66
// we'll get automatic cleanup between tests.
7-
test('first', () => {
8-
render(<div>hi</div>)
7+
test('first', async () => {
8+
await render(<div>hi</div>)
99
})
1010

1111
test('second', () => {

src/__tests__/cleanup.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import {render, cleanup} from '../'
33

4-
test('cleans up the document', () => {
4+
test('cleans up the document', async () => {
55
const spy = jest.fn()
66
const divId = 'my-div'
77

@@ -16,18 +16,18 @@ test('cleans up the document', () => {
1616
}
1717
}
1818

19-
render(<Test />)
20-
cleanup()
19+
await render(<Test />)
20+
await cleanup()
2121
expect(document.body).toBeEmptyDOMElement()
2222
expect(spy).toHaveBeenCalledTimes(1)
2323
})
2424

25-
test('cleanup does not error when an element is not a child', () => {
26-
render(<div />, {container: document.createElement('div')})
27-
cleanup()
25+
test('cleanup does not error when an element is not a child', async () => {
26+
await render(<div />, {container: document.createElement('div')})
27+
await cleanup()
2828
})
2929

30-
test('cleanup runs effect cleanup functions', () => {
30+
test('cleanup runs effect cleanup functions', async () => {
3131
const spy = jest.fn()
3232

3333
const Test = () => {
@@ -36,8 +36,8 @@ test('cleanup runs effect cleanup functions', () => {
3636
return null
3737
}
3838

39-
render(<Test />)
40-
cleanup()
39+
await render(<Test />)
40+
await cleanup()
4141
expect(spy).toHaveBeenCalledTimes(1)
4242
})
4343

@@ -55,7 +55,7 @@ describe('fake timers and missing act warnings', () => {
5555
jest.useRealTimers()
5656
})
5757

58-
test('cleanup does not flush microtasks', () => {
58+
test('cleanup does not flush microtasks', async () => {
5959
const microTaskSpy = jest.fn()
6060
function Test() {
6161
const counter = 1
@@ -77,17 +77,17 @@ describe('fake timers and missing act warnings', () => {
7777

7878
return null
7979
}
80-
render(<Test />)
80+
await render(<Test />)
8181

82-
cleanup()
82+
await cleanup()
8383

8484
expect(microTaskSpy).toHaveBeenCalledTimes(0)
8585
// console.error is mocked
8686
// eslint-disable-next-line no-console
8787
expect(console.error).toHaveBeenCalledTimes(0)
8888
})
8989

90-
test('cleanup does not swallow missing act warnings', () => {
90+
test('cleanup does not swallow missing act warnings', async () => {
9191
const deferredStateUpdateSpy = jest.fn()
9292
function Test() {
9393
const counter = 1
@@ -109,10 +109,10 @@ describe('fake timers and missing act warnings', () => {
109109

110110
return null
111111
}
112-
render(<Test />)
112+
await render(<Test />)
113113

114114
jest.runAllTimers()
115-
cleanup()
115+
await cleanup()
116116

117117
expect(deferredStateUpdateSpy).toHaveBeenCalledTimes(1)
118118
// console.error is mocked

src/__tests__/debug.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ afterEach(() => {
99
console.log.mockRestore()
1010
})
1111

12-
test('debug pretty prints the container', () => {
12+
test('debug pretty prints the container', async () => {
1313
const HelloWorld = () => <h1>Hello World</h1>
14-
const {debug} = render(<HelloWorld />)
14+
const {debug} = await render(<HelloWorld />)
1515
debug()
1616
expect(console.log).toHaveBeenCalledTimes(1)
1717
expect(console.log).toHaveBeenCalledWith(
1818
expect.stringContaining('Hello World'),
1919
)
2020
})
2121

22-
test('debug pretty prints multiple containers', () => {
22+
test('debug pretty prints multiple containers', async () => {
2323
const HelloWorld = () => (
2424
<>
2525
<h1 data-testid="testId">Hello World</h1>
2626
<h1 data-testid="testId">Hello World</h1>
2727
</>
2828
)
29-
const {debug} = render(<HelloWorld />)
29+
const {debug} = await render(<HelloWorld />)
3030
const multipleElements = screen.getAllByTestId('testId')
3131
debug(multipleElements)
3232

@@ -36,9 +36,9 @@ test('debug pretty prints multiple containers', () => {
3636
)
3737
})
3838

39-
test('allows same arguments as prettyDOM', () => {
39+
test('allows same arguments as prettyDOM', async () => {
4040
const HelloWorld = () => <h1>Hello World</h1>
41-
const {debug, container} = render(<HelloWorld />)
41+
const {debug, container} = await render(<HelloWorld />)
4242
debug(container, 6, {highlight: false})
4343
expect(console.log).toHaveBeenCalledTimes(1)
4444
expect(console.log.mock.calls[0]).toMatchInlineSnapshot(`

src/__tests__/end-to-end.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ describe.each([
5353
}
5454

5555
test('waitForElementToBeRemoved', async () => {
56-
render(<ComponentWithMacrotaskLoader />)
56+
await render(<ComponentWithMacrotaskLoader />)
5757
const loading = () => screen.getByText('Loading...')
5858
await waitForElementToBeRemoved(loading)
5959
expect(screen.getByTestId('message')).toHaveTextContent(/Hello World/)
6060
})
6161

6262
test('waitFor', async () => {
63-
render(<ComponentWithMacrotaskLoader />)
63+
await render(<ComponentWithMacrotaskLoader />)
6464
await waitFor(() => screen.getByText(/Loading../))
6565
await waitFor(() => screen.getByText(/Loaded this message:/))
6666
expect(screen.getByTestId('message')).toHaveTextContent(/Hello World/)
6767
})
6868

6969
test('findBy', async () => {
70-
render(<ComponentWithMacrotaskLoader />)
70+
await render(<ComponentWithMacrotaskLoader />)
7171
await expect(screen.findByTestId('message')).resolves.toHaveTextContent(
7272
/Hello World/,
7373
)
@@ -137,14 +137,14 @@ describe.each([
137137
}
138138

139139
test('waitForElementToBeRemoved', async () => {
140-
render(<ComponentWithMicrotaskLoader />)
140+
await render(<ComponentWithMicrotaskLoader />)
141141
const loading = () => screen.getByText('Loading..')
142142
await waitForElementToBeRemoved(loading)
143143
expect(screen.getByTestId('message')).toHaveTextContent(/Hello World/)
144144
})
145145

146146
test('waitFor', async () => {
147-
render(<ComponentWithMicrotaskLoader />)
147+
await render(<ComponentWithMicrotaskLoader />)
148148
await waitFor(() => {
149149
screen.getByText('Loading..')
150150
})
@@ -155,7 +155,7 @@ describe.each([
155155
})
156156

157157
test('findBy', async () => {
158-
render(<ComponentWithMicrotaskLoader />)
158+
await render(<ComponentWithMicrotaskLoader />)
159159
await expect(screen.findByTestId('message')).resolves.toHaveTextContent(
160160
/Hello World/,
161161
)

src/__tests__/events.js

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,16 @@ eventTypes.forEach(({type, events, elementType, init}) => {
151151
1,
152152
)}`
153153

154-
it(`triggers ${propName}`, () => {
154+
it(`triggers ${propName}`, async () => {
155155
const ref = React.createRef()
156156
const spy = jest.fn()
157157

158-
render(
159-
React.createElement(elementType, {
160-
[propName]: spy,
161-
ref,
162-
}),
163-
)
158+
await render(React.createElement(elementType, {
159+
[propName]: spy,
160+
ref,
161+
}))
164162

165-
fireEvent[eventName](ref.current, init)
163+
await fireEvent[eventName](ref.current, init)
166164
expect(spy).toHaveBeenCalledTimes(1)
167165
})
168166
})
@@ -179,7 +177,7 @@ eventTypes.forEach(({type, events, elementType, init}) => {
179177
nativeEventName = 'dblclick'
180178
}
181179

182-
it(`triggers native ${nativeEventName}`, () => {
180+
it(`triggers native ${nativeEventName}`, async () => {
183181
const ref = React.createRef()
184182
const spy = jest.fn()
185183
const Element = elementType
@@ -195,59 +193,54 @@ eventTypes.forEach(({type, events, elementType, init}) => {
195193
return <Element ref={ref} />
196194
}
197195

198-
render(<NativeEventElement />)
196+
await render(<NativeEventElement />)
199197

200-
fireEvent[eventName](ref.current, init)
198+
await fireEvent[eventName](ref.current, init)
201199
expect(spy).toHaveBeenCalledTimes(1)
202200
})
203201
})
204202
})
205203
})
206204

207-
test('onChange works', () => {
205+
test('onChange works', async () => {
208206
const handleChange = jest.fn()
209207
const {
210208
container: {firstChild: input},
211-
} = render(<input onChange={handleChange} />)
212-
fireEvent.change(input, {target: {value: 'a'}})
209+
} = await render(<input onChange={handleChange} />)
210+
await fireEvent.change(input, {target: {value: 'a'}})
213211
expect(handleChange).toHaveBeenCalledTimes(1)
214212
})
215213

216-
test('calling `fireEvent` directly works too', () => {
214+
test('calling `fireEvent` directly works too', async () => {
217215
const handleEvent = jest.fn()
218216
const {
219217
container: {firstChild: button},
220-
} = render(<button onClick={handleEvent} />)
221-
fireEvent(
222-
button,
223-
new Event('MouseEvent', {
224-
bubbles: true,
225-
cancelable: true,
226-
button: 0,
227-
}),
228-
)
218+
} = await render(<button onClick={handleEvent} />)
219+
await fireEvent(button, new Event('MouseEvent', {
220+
bubbles: true,
221+
cancelable: true,
222+
button: 0,
223+
}))
229224
})
230225

231-
test('blur/focus bubbles in react', () => {
226+
test('blur/focus bubbles in react', async () => {
232227
const handleBlur = jest.fn()
233228
const handleBubbledBlur = jest.fn()
234229
const handleFocus = jest.fn()
235230
const handleBubbledFocus = jest.fn()
236-
const {container} = render(
237-
<div onBlur={handleBubbledBlur} onFocus={handleBubbledFocus}>
238-
<button onBlur={handleBlur} onFocus={handleFocus} />
239-
</div>,
240-
)
231+
const {container} = await render(<div onBlur={handleBubbledBlur} onFocus={handleBubbledFocus}>
232+
<button onBlur={handleBlur} onFocus={handleFocus} />
233+
</div>)
241234
const button = container.firstChild.firstChild
242235

243-
fireEvent.focus(button)
236+
await fireEvent.focus(button)
244237

245238
expect(handleBlur).toHaveBeenCalledTimes(0)
246239
expect(handleBubbledBlur).toHaveBeenCalledTimes(0)
247240
expect(handleFocus).toHaveBeenCalledTimes(1)
248241
expect(handleBubbledFocus).toHaveBeenCalledTimes(1)
249242

250-
fireEvent.blur(button)
243+
await fireEvent.blur(button)
251244

252245
expect(handleBlur).toHaveBeenCalledTimes(1)
253246
expect(handleBubbledBlur).toHaveBeenCalledTimes(1)

src/__tests__/multi-base.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ afterAll(() => {
1515
treeB.parentNode.removeChild(treeB)
1616
})
1717

18-
test('baseElement isolates trees from one another', () => {
19-
const {getByText: getByTextInA} = render(<div>Jekyll</div>, {
18+
test('baseElement isolates trees from one another', async () => {
19+
const {getByText: getByTextInA} = await render(<div>Jekyll</div>, {
2020
baseElement: treeA,
2121
})
22-
const {getByText: getByTextInB} = render(<div>Hyde</div>, {
22+
const {getByText: getByTextInB} = await render(<div>Hyde</div>, {
2323
baseElement: treeB,
2424
})
2525

0 commit comments

Comments
 (0)