enzymejs/enzyme

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

Open

#2367 aperta il 7 apr 2020

Vedi su GitHub
 (11 commenti) (0 reazioni) (0 assegnatari)JavaScript (2016 fork)batch import
docshelp wanted

Metriche repository

Star
 (19.979 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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!

Guida contributor