-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enables finding nodes created by forwardRef #2
base: forward-ref
Are you sure you want to change the base?
Conversation
@@ -113,11 +113,21 @@ function toTree(vnode) { | |||
} | |||
case HostText: // 6 | |||
return node.memoizedProps; | |||
case ForwardRef: { |
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.
This is the crux of the change. I realise that this toTree
function is largely adapted from toTree
in react-test-renderer
. This creates a divergence in behaviour between the two libraries which sounds scary. Ideally, this change would go into react-test-renderer
and then enzyme could use the toTree function directly.
return { | ||
nodeType: 'function', | ||
type: node.type, | ||
props: { ...node.pendingProps }, |
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.
why pendingProps? is that all that's there on this fiber?
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.
Please don't use pendingProps
anywhere.
In fact all of the fields Enzyme uses are subject to breakage. But I guess we talked about this before.
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.
Yeah I was really just feeling around in the dark here. I used pendingProps because that looked like it had the information I needed. Is it any worse than memoizedProps
that the other tags use?
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.
pendingProps
get cleared by React after rendering. So yes, it's worse and shouldn't be read.
@@ -113,11 +113,21 @@ function toTree(vnode) { | |||
} | |||
case HostText: // 6 | |||
return node.memoizedProps; | |||
case ForwardRef: { | |||
return { | |||
nodeType: 'function', |
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.
hmm we should probably have a new type for this, but that would require much wider enzyme changes cc @aweary I think this is ok for now?
// The node type can be defined in three different places. | ||
// Where the type is depends on the node and rendering strategy. | ||
// This function looks in the three spots and returns the type. | ||
const getNodeType = (node) => { |
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 think you can use typeOf
from react-is
for this, no?
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 think i tried that and it didn't work...the node
here isn't an element, which i think is what is expected by react-is
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.
Aah okay
@jquense has there been any attempts to make an adapter based on |
62a06f6
to
f818a17
Compare
f0c7b6a
to
6be05e9
Compare
7fc51c1
to
d7a4ab3
Compare
b90bc58
to
965b785
Compare
Hi mate, I have made some further changes based on your initial work to support
forwardRef
.While I was able to render
forwardRef
nodes in my tests, I ran into problems when trying to find those components. This is becauseforwardRef
nodes are skipped in thetoTree
method. I explained the problem in more detail on this issue.These changes make
forwardRef
nodes look more similar to functional or class-based react nodes.We currently have a large codebase using Enzyme, so hopefully tomorrow I'll get a chance to test this fork out against that codebase.