DEV Community

Cover image for What to Unit Test in a Vue App (And What Not to Touch)
Jakub Andrzejewski
Jakub Andrzejewski

Posted on

What to Unit Test in a Vue App (And What Not to Touch)

Unit testing is often treated as a checkbox on a project’s checklist. Teams either try to test everything or avoid tests altogether because they feel slow, brittle, or hard to maintain.

In Vue applications, the real challenge isn’t how to write unit tests — it’s what is actually worth testing.

Testing the wrong things leads to fragile tests, constant refactoring pain, and a false sense of confidence. Testing the right things creates a safety net that enables refactoring, faster development, and long-term maintainability.

In this article, we’ll explore:

  • What unit tests are truly good at in Vue apps
  • Which parts of your codebase deserve unit tests
  • What not to unit test (and why)
  • How to define pragmatic testing boundaries
  • How to keep tests valuable instead of burdensome

Enjoy!

🤔 What Is the Purpose of Unit Tests in Vue?

Unit tests are not meant to prove that Vue works. Vue itself is already heavily tested.

The real purpose of unit tests in a Vue application is to:

  • Protect business logic
  • Validate critical decision paths
  • Enable safe refactoring
  • Catch regressions early
  • Document expected behavior

A good unit test answers this question:

“If this logic breaks, would it meaningfully affect the user or the business?”

If the answer is no, that code probably doesn’t need a unit test.

🟢 What You Should Unit Test in a Vue App

Business Logic and Pure Functions

Anything that contains decision-making logic is a prime candidate for unit testing.

Examples:

  • Price calculations
  • Validation rules
  • Permission checks
  • Data transformations
  • Formatting logic

If it’s a pure function with inputs and outputs, it should almost always be tested.

function calculateDiscount(price: number, isPremium: boolean) {
  return isPremium ? price * 0.8 : price
}
Enter fullscreen mode Exit fullscreen mode

This logic is easy to test, stable over time, and critical to correctness.

Composables with Logic (Not Just Glue)

Composables that encapsulate logic — not just re-export state — are excellent testing targets.

Good candidates:

  • Data fetching composables
  • State machines
  • Feature-flag logic
  • Complex reactive flows
export function useUserAccess(user) {
  return computed(() => user.role === 'admin')
}
Enter fullscreen mode Exit fullscreen mode

If a composable makes decisions, unit tests add real value.

Store Logic (Actions, Getters, Rules)

Stores are not just state containers — they often encode business rules.

You should test:

  • Actions that modify state
  • Getters with logic
  • Error handling paths
  • Side-effect orchestration

What you usually don’t need to test:

  • Simple state assignments
  • Trivial getters that just return a value

Test behavior, not implementation details.

Edge Cases and Failure Paths

Unit tests shine when validating:

  • Error states
  • Empty data
  • Invalid input
  • Boundary conditions

These are the scenarios that often break silently in production and are hardest to reason about without tests.

🟢 What You Should Not Unit Test

Vue Internals and Framework Behavior

You don’t need to test:

  • That v-if works
  • That v-model updates correctly
  • That reactivity updates the DOM
  • That lifecycle hooks are called

Vue already guarantees these behaviors. Testing them adds noise without value.

Markup and Styling Details

Avoid unit tests that assert:

  • Exact HTML structure
  • CSS classes unless they affect logic
  • Pixel-perfect rendering

These tests are brittle and break on harmless refactors.

If appearance matters, use:

  • Visual testing
  • Snapshot testing (sparingly)
  • End-to-end tests

Components That Are Pure Composition

If a component:

  • Only wires props to children
  • Contains no logic
  • Has no branching behavior

…it usually doesn’t need unit tests.

Testing such components often duplicates what integration or E2E tests already cover better.

Implementation Details

Avoid tests that depend on:

  • Internal variable names
  • Specific reactive structures
  • Internal refs or watchers

Good tests verify observable behavior, not how that behavior is implemented.

🟢 Defining Pragmatic Testing Boundaries

A healthy Vue testing strategy looks like this:

  • Unit tests protect logic
  • Integration tests protect collaboration between components
  • E2E tests protect user flows

Ask yourself:

  • Would this test fail if the behavior broke?
  • Would this test survive a refactor?
  • Does this test increase confidence or just coverage?

High-value tests are:

  • Focused
  • Stable
  • Intentional

Low-value tests are:

  • Fragile
  • Redundant
  • Framework-dependent

The goal is not maximum coverage — it’s maximum confidence per test written.

📖 Learn more

If you would like to learn more about Vue, Nuxt, JavaScript or other useful technologies, checkout VueSchool by clicking this link or by clicking the image below:

Vue School Link

It covers most important concepts while building modern Vue or Nuxt applications that can help you in your daily work or side projects 😉

🧪 Advance skills

A certification boosts your skills, builds credibility, and opens doors to new opportunities. Whether you're advancing your career or switching paths, it's a smart step toward success.

Check out Certificates.dev by clicking this link or by clicking the image below:

Certificates.dev Link

Invest in yourself—get certified in Vue.js, JavaScript, Nuxt, Angular, React, and more!

✅ Summary

Unit testing in Vue is not about testing everything — it’s about testing the right things.

Well-chosen tests enable confidence and speed.
Poorly chosen tests slow teams down and provide little value.

Test intentionally — your future self will thank you.

Take care!

And happy coding as always 🖥️

Top comments (0)