Skip to content

findBy* and waitForElement* not returning HTMLElement anymore (since 6.1.0) (works in dom-testing-library) #345

Closed
@joual

Description

@joual
  • react-testing-library version: 6.1.x
  • react version: ^16.8.3
  • node version: 10.15.x
  • npm (or yarn) 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions