Spying on
React.useState and asserting its setter was called with 1Spying on React.useState is the test coupled to implementation details. Whether a component uses useState, useReducer or an external store is an internal choice. A test that checks it breaks on a refactor, even when the UI still works. The tempting wrong pick is the onSubmit option. But the onSubmit callback is a prop, so it is part of the component's public API. Asserting on it is fine.
Read more
- Guiding principles (https://testing-library.com/docs/guiding-principles)testing-library.com