Avoiding component mocks
This section covers how to build your application without using component mocks. Of course, the application we’ve built up to this point hasn’t used any, so you already know it’s possible.
The SvelteKit application we’ve built has a page route component that renders a list of Birthday
components and a BirthdayForm
component. Both of these components are covered by their own test suites, so they are certainly candidates for using component mocks. The page route component would simply check that it renders Birthday
and BirthdayForm
in the right way, and avoid testing any of the birthdays themselves.
But there’s not much point in doing this. Neither of these components has any behavior on mount, so there’s no trouble in letting them render.
The biggest risk you have in not using component mocks is that of overtesting. This is when you repeat the tests of a child component in the tests for the parent component...