Closed
Description
react-testing-library
version: 6.1.xreact
version: ^16.8.3node
version: 10.15.xnpm
(oryarn
) version: 6.9.0
Relevant code or config:
The following test fails in react-testing-library
test('findByTestId returns the element', async () => {
const ref = React.createRef()
const {findByTestId, getByTestId} = render(
<div ref={ref} data-testid="foo" />,
)
await expect(findByTestId('foo')).resolves.toEqual(getByTestId('foo'))
})
While the following test passes in dom-testing-library
test('waits for element to appear in a specified container', async () => {
const {rerender, container, getByTestId} = render('<div />')
const promise = waitForElement(() => getByTestId('div'), {container})
setTimeout(() => rerender('<div data-testid="div" />'))
const element = await promise
expect(element).toEqual(getByTestId('div'))
})
What you did:
I was trying to use the findByTestId
API to grab an element.
What happened:
The resolved value is undefined in react-testing-library 6.1.x but returns fine in 6.0.0.
Reproduction:
See the above scenarios above.
Problem description:
Code that used to leverage the elements returned by findBy* and waitFor* will now start to fail.
Suggested solution:
I suspect this has to do with the recent asyncWrapper addition, which is set to cb => cb()
in DTL but likely something that doesn't return the value in RTL.