Skip to content

findBy/findByAll not working with within #259

Closed
@nilshartmann

Description

@nilshartmann

Describe the bug
Using a findBy and findAllBy query function on a selector returned by within throws error:

1) Function that specifies a selector can only return a DOM node, an array of nodes, NodeList, HTMLCollection, null or undefined. Use ClientFunction to
      return other values.

In my example the following works:

 const group = screen.findByRole("group", { name: "My Group" });

  await t
    .expect(
      within(group).getByRole("button", { name: "Increase B" }).exists
    )
    .ok();

while this one does not:

 const group = screen.findByRole("group", { name: "My Group" });

 await t
    .expect(
      within(group).findByRole("button", { name: "Increase B" }).exists
    )
    .ok();

It doesn't matter if I find the group with findByRole or getByRole.

To Reproduce

You can find a reproducable example at https://github.com/nilshartmann/testcafe-within. The app in this repository is a create-react-app-based example.

  1. Clone the repo
  2. yarn install
  3. yarn start
  4. in second terminal: yarn testcafe

Testfile: https://github.com/nilshartmann/testcafe-within/blob/master/testcafe/within.test.ts

Versions:

"@testing-library/testcafe": "^4.3.0",
 "testcafe": "^1.9.4"

Expected behavior

I'd expect that findBy should also work with selectors from within?

Desktop (please complete the following information):

  • OS: 10.15.7
  • Browser: firefox, chrome
  • Version Chrome 87.0.4280.67

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions