I have helpers set up for my React tests using the testing library:
const getSomething = (name: string, container: Screen | any = screen) {
return container.getByRole('someRole', { name: name })
}
The container
can be either the default screen
from react testing or it can come from the testing library like this:
const myParentElement = screen.getByRole('cell', { name: 'foo' })
const myElement = getSomething("myName", within(myParentElement))
I am looking to replace the any
in container: Screen | any
with the correct type that is returned by using within
. How can I achieve this?
Note: within
is an alias for getQueriesForElement
, which is defined here on testing-library