Cypress or unit testing (Jasmine, Karma, or Jest): What are the benefits of using these?

posted 2 min read

What is enough to test and maintain an application?

Understanding when to use Cypress (E2E testing) versus unit testing (Jasmine/Karma or Jest) is key to building a reliable and maintainable Angular app. Each has its own purpose and benefits, and ideally, you combine both depending on the scope of what you're testing.


Unit Testing (Jasmine/Karma or Jest)

Best for:

  • Testing individual components, services, pipes, directives in isolation.
  • Ensuring logic correctness (e.g. functions return correct results).
  • Fast feedback loop (runs quickly).

Advantages:

  • Fast and easy to debug.
  • Encourages good architecture (decoupling).
  • Very effective for testing pure logic and component behavior.

Limitations:

  • Doesn’t test actual rendering in a real browser.
  • Doesn’t catch integration issues (e.g., routing, APIs, DOM behavior).
  • Requires mocking a lot of dependencies (can lead to false positives).

End-to-End (E2E) Testing with Cypress

Best for:

  • Testing the app as a real user would — in a real browser, with real clicks, navigation, and backend interactions.
  • Verifying integration across multiple components, routing, services.
  • Critical user flows (login, checkout, form submission, etc.).

Advantages:

  • Runs in a real browser → better confidence that the app actually works.
  • Simulates real-world usage.
  • Built-in wait, retries, and developer-friendly debug tools.
  • Easy to write readable, behavior-focused tests.

Limitations:*

  • Slower than unit tests.
  • Can be flaky if not written carefully (e.g., relying on fixed timeouts).
  • Requires running the actual Angular app (more setup).

So, Should You Use Cypress If You Have Unit Tests?

Yes — Cypress complements unit tests.

Scenario Use Unit Tests Use Cypress
Pure logic in services ✅ Yes ❌ No
Component method behavior ✅ Yes ❌ No
DOM interactions (clicks, inputs) ✅ (shallow) ✅ (realistic)
Form validation ✅ (logic) ✅ (user experience)
Login flow ❌ No ✅ Yes
Routing between pages ❌ No ✅ Yes
API + UI integration ❌ No ✅ Yes

Hybrid Strategy (Recommended)

  • Use unit tests (Jasmine/Jest) to cover 70-80% of your app:

    • Logic
    • UI behavior
    • Services
  • Use Cypress (E2E) to cover:

    • Core user journeys (e.g., login, registration, checkout)
    • Critical flows that span multiple components/services

TL;DR Recommendation

Tool Use for Benefit
Jasmine/Karma or Jest Fast, isolated tests Quick feedback, high coverage
Cypress Full browser, real-user tests Confidence in real-world usage

Using only unit tests risks missing integration bugs. Using only E2E tests can be too slow and brittle.

Best practice: Use both together to ensure depth (unit) and breadth (E2E) in your test coverage.


If you read this far, tweet to the author to show them you care. Tweet a Thanks

I’ve used Cypress with Vue, and while it took some time to write proper dynamic tests, the upside is that the entire application is now fully covered with end-to-end testing.

More Posts

Optimizing Software Testing with the 80/20 Rule: A Strategic Approach to Unit and Integration Testing

Aditya Pratap Bhuyan - Jun 6

Cranes, Arches, and the End of Capitalism: What Software Development Reveals About the Future We Are Building

Landon - Mar 31

Lessons from a Year of Side Projects: What Actually Worked (and What Didn’t)

Sourav Bandyopadhyay - Jun 24

Unit Testing in Python

Abdul Daim - Apr 4, 2024

Performance of Performance Testing: JMeter Script Optimization with VisualVM

bugnificent - Jun 17
chevron_left