Skip to content

Commit c660280

Browse files
author
Kent C. Dodds
committed
fix(act): ensure that the result is returned from our wrapper
Closes #345
1 parent 6cbc982 commit c660280

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/__tests__/act.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ test('render calls useEffect immediately', () => {
1616

1717
test('findByTestId returns the element', async () => {
1818
const ref = React.createRef()
19-
const {findByTestId, getByTestId} = render(
20-
<div ref={ref} data-testid="foo" />,
21-
)
22-
await expect(findByTestId('foo')).resolves.toEqual(getByTestId('foo'))
19+
const {findByTestId} = render(<div ref={ref} data-testid="foo" />)
20+
expect(await findByTestId('foo')).toBe(ref.current)
2321
})
2422

2523
test('fireEvent triggers useEffect calls', () => {

src/act-compat.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ async function asyncActPolyfill(cb) {
5656
)
5757
youHaveBeenWarned = true
5858
}
59-
const result = await cb()
59+
await cb()
6060
// make all effects resolve after
6161
act(() => {})
62-
return result
6362
}
6463

6564
// istanbul ignore next

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import {
99
import act, {asyncAct} from './act-compat'
1010

1111
configureDTL({
12-
asyncWrapper: asyncAct,
12+
asyncWrapper: async cb => {
13+
let result
14+
await asyncAct(async () => {
15+
result = await cb()
16+
})
17+
return result
18+
},
1319
})
1420

1521
const mountedContainers = new Set()

0 commit comments

Comments
 (0)