Skip to content

Commit 021ef9d

Browse files
joualKent C. Dodds
authored and
Kent C. Dodds
committed
fix(act): ensure that the result is returned from our wrapper (#346)
* failing test * act-compat change * fix(act): ensure that the result is returned from our wrapper Closes #345 Closes #347
1 parent 30bf1c6 commit 021ef9d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/__tests__/act.js

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ test('render calls useEffect immediately', () => {
1414
expect(effectCb).toHaveBeenCalledTimes(1)
1515
})
1616

17+
test('findByTestId returns the element', async () => {
18+
const ref = React.createRef()
19+
const {findByTestId} = render(<div ref={ref} data-testid="foo" />)
20+
expect(await findByTestId('foo')).toBe(ref.current)
21+
})
22+
1723
test('fireEvent triggers useEffect calls', () => {
1824
const effectCb = jest.fn()
1925
function Counter() {

src/index.js

+7-1
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)