testing-library/playwright-testing-library

getQueriesForElement is not returned by getByRole

davidchai717 opened this issue ยท 3 comments

Playwright version: 1.20.2
Playwright Testing Lib version: 4.2.1

I was trying to do something like this:

const $secondaryNav = (
  await getByRole("navigation", {
    name: "Secondary Navigation Menu"
  })
).getQueriesForElement();

However it kept throwing a type error "getQueriesForElement is not a function".

Am I doing something wrong here? I can also confirm the getByRole query does return the proper element.

Hi @davidchai717, I'm so sorry it looks like the documentation was incorrect there. I'm assuming you are using the @playwright/test fixture? I went ahead and fixed the documentation in #412, but for your snippet there you'd want:

import { getQueriesForElement } from '@playwright-testing-library/test/fixture';

// ...

const $secondaryNav = getQueriesForElement(
  await getByRole("navigation", {
    name: "Secondary Navigation Menu"
  })
);

... or alternatively use within, as it's aliased to getQueriesForElement just like in @testing-library/dom:

import { within } from '@playwright-testing-library/test/fixture';

// ...

const $secondaryNav = within(
  await getByRole("navigation", {
    name: "Secondary Navigation Menu"
  })
);

Let me know if you still have any issues after trying the above suggestion and thank you for reporting this!

๐ŸŽ‰ This issue has been resolved in version 4.3.0-beta.1 ๐ŸŽ‰

The release is available on:

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

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

The release is available on:

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