Mistake: Testing Implementation
Question
What is wrong with this component test?
Code
test('counter', () => {
const wrapper = mount(Counter);
expect(wrapper.vm.count).toBe(0); // internal state
wrapper.vm.increment(); // calling internal method
expect(wrapper.vm.count).toBe(1); // internal state
});
Hint
Tests should verify behavior, not internal state.
Explanation
The mistake is testing internal implementation details (.vm.count and .vm.increment()). These are private to the component and may change during refactoring, breaking the test. The fix: test through the public interface — render the component, interact with it like a user (click the button), and check the visible output (the displayed count).
Related Resources
Related Lessons
- Test Best Practices
Writing maintainable tests.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.