CodePark/ questions / Strategy & test types
START PRACTICINGPRACTICE
Frontend question · Testing › Strategy & test types

Which of these tests is coupled to implementation details and is likely to break during a harmless refactor?

Spying on React.useState and asserting its setter was called with 1

Spying 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.