-
Notifications
You must be signed in to change notification settings - Fork 222
Add generics to findWhere and findWhereAll in react-testing #1999
Conversation
packages/react-testing/README.md
Outdated
function Wrapper() { | ||
return ( | ||
<> | ||
<MyComponent name="Michelle" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The find docs reference you and Gord, I'm just being consistent :p
packages/react-testing/README.md
Outdated
(node) => node.is(MyComponent) && node.prop('name').startsWith('M'), | ||
); | ||
|
||
const startsWithG = wrapper.findWhere<MyComponent>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually a little surprise its wrapper.findWhere<MyComponent>
and not wrapper.findWhere<type of MyComponent>
, the new version of TS got smarter again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent spot, the typeof
totally needs to be there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol it would be so nice if typescript is smart enough in the future to know it should use the typeof
in generic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 locally with Ben and it looks good to me!
Description
findWhere
andfindAllWhere
previously always returnedElement<unknown>
which meant that code didn't know the type of the element returned And thus you got TS errors (forgive this trivial example, where usingfind
would be preferred):This PR adds a generic type to
findWhere
and findAllWhere` so that you can specify the type of element that you shall be returning.This generic type is either a string referring to a html element (
'div'
,'form'
etc), or a React component (Card
etc). This is the same type as what you can pass intofind
as it's first argument.Type of change