testing-library / testcafe-testing-library

:ox: Simple and complete custom Selectors for Testcafe that encourage good testing practices.
http://npm.im/@testing-library/testcafe
MIT License
71 stars 15 forks source link

Support ClientFunctions for findByRole's name option #354

Open dantman opened 2 years ago

dantman commented 2 years ago

Is your feature request related to a problem? Please describe. I had a list of buttons containing years and wanted to do a numeric comparison to a year number in a variable instead of a string comparison. findByRole's types suggest that it supports a function form of the name option and thought that would work.

However because the name function is executed on the client it loses the context necessary to work (i.e. the function cannot use any variable outside it).

Describe the solution you'd like testcafe has an API for supporting this. Its ClientFunction API allows defining dependencies that will be passed to the ClientFunction's context.

It would be great if we could pass a ClientFunction to the name option of findByRole so we could define our own ClientFunction with any dependencies we need.

benmonro commented 2 years ago

Thanks for reporting @dantman would love a PR if you want to take a stab at it. :)