Skip to content
Testing·Intermediate·Conceptual·1 min read

What's wrong with asserting expect(onChange).toHaveBeenCalledTimes(1) as a test's main check?

Short interview answer

It couples the test to the component's internal wiring rather than its effect. If the component is refactored to call onChange differently but produce the same user-visible result, the test breaks for no real reason; asserting on the resulting rendered state is more durable.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Testing React components

Related questions