enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.96k stars 2.01k forks source link

Explain how the synchronization works #2598

Closed PierreTurnbull closed 1 year ago

PierreTurnbull commented 1 year ago

Is your feature request related to a problem? Please describe.

It's not clear to me how Enzyme synchronizes its tree with the React tree. The mere existence of this mechanism and the need for manually updating the tree when changes are made externally is clear, but the details of it, such as what exactly is "externally" or how is asynchronicity dealt with are not. I would love to learn more about it. The lack of these information is making it harder for me to test pieces of code that contain asynchronicity.

Describe the solution you'd like

A piece of dedicated documentation explaining in details how the synchronization works, especially what kind of change does trigger or does not trigger the synchronization (for example a setState will, but not if it is located in a Promise.).

Describe alternatives you've considered

I've asked a question on Stack Overflow but have received 0 response yet, I'ved asked Google and ChatGPT but I didn't get any meaningful answer.

Additional context

You can check my SO post for a more concrete approach of the subject.

ljharb commented 1 year ago

I commented on SO:

That's because in the first case, setLogo runs synchronously/immediately. In the second, it runs on a successive tick. If you added an await null; in there before the setLogo, the first and second cases would be identical.

This isn't how enzyme works, it's how JavaScript works.