enzymejs/enzyme

Please some information about find() as a snapshot to docs

Open

#2,367 opened on Apr 7, 2020

View on GitHub
 (11 comments) (0 reactions) (0 assignees)JavaScript (2,016 forks)batch import
docshelp wanted

Repository metrics

Stars
 (19,979 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Current behavior

Hello, I would simply like to request that the documentation for find() (https://enzymejs.github.io/enzyme/docs/api/ShallowWrapper/find.html) be updated to reflect its snapshot-nature. For example, in a situation where clicking a button updates state under the hood...

   // some set up code goes here. 

    const deleteButton = wrapper.find('[data-enzyme-id="someid"]').first();
    deleteButton.simulate('click');

    expect(wrapper.find("#modal").first().props().isOpen).toBe(true)

the above code will work, but the below will not:

    const modals = wrapper.find("#modal");
    const deleteButton = wrapper.find('[data-enzyme-id="someid"]').first();
    deleteButton.simulate('click');

    expect(modals.first().props().isOpen).toBe(true)

Presumably, this is because the objects that are returned by find() do not reflect the actual DOM tree, but a snapshot thereof.

It would be great to see this mentioned briefly in the documentation. Please suggest a way to explain this in a documentation-appropriate manner. Thank you!

Contributor guide