testing-library/playwright-testing-library

findByRole: Unable to query heading by level

weyert opened this issue ยท 3 comments

I am trying to query a h1 element by using the following: findByRole('heading', { name: /Applications/i, level: 1 }) as suggesting on testing-library.com but this appears not to be working when using this library.

The following error is shown:

  elementHandle.evaluateHandle: Error: Found multiple elements with the role "heading" and name `/Applications/i`

    Here are the matching elements:

    <h1
      class="text-2xl font-bold leading-7 text-gray-900 sm:text-3xl sm:leading-9 sm:truncate"
    >
      Available Applications
    </h1>

    <h4
      class="mb-3 text-sm font-medium leading-tight text-gray-500 uppercase sr-only"
      id="group-title-1"
    >
      Available Applications
    </h4>

Hi @weyert, thanks for the report here. It looks like support for level was added in @testing-library/dom 7.23 and we were on 7.22. I'm planning on upgrading to 8.x soon, but I will probably be releasing that as a major version. In the meantime, I upgraded to the latest 7.x and fixed the types for the options object in #379 :)

๐ŸŽ‰ This issue has been resolved in version 4.2.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

Awesome, thank you very much :) ๐Ÿค—