enzymejs / enzyme

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

Is simulate() still deprecated? #2530

Closed mferber closed 3 years ago

mferber commented 3 years ago

Issue #2173 (June 2019) says simulate() is deprecated, but as of mid-2021 the docs haven't been updated. The issue says "A PR to make this clear in the docs would be welcomed," but the resulting PR (https://github.com/enzymejs/enzyme/pull/2182) has been sitting around unmerged for 2 years. Should we still consider the deprecation an official statement, or was that just one developer's opinion?

(Reason for asking: disagreement over whether to use simulate() in new code)

ljharb commented 3 years ago

It is one developer’s opinion - mine - but since I’m the only developer on enzyme, it’s also an official statement.

Avoid use of simulate in all code, new or otherwise. It doesn’t faithfully simulate anything.

mferber commented 3 years ago

Thank you! (I win the argument. :-) )

arvinsim commented 2 years ago

Wait, so if I want to do fire a onChange event, I should not use .simulate('change', { target: { value: "someValue" } })?

If so what is the correct way to do it? .props().onChange()?

ljharb commented 2 years ago

@arvinsim yes, precisely, altho you can also do .invoke('onChange')({ target: { value: 'someValue' } }).