angularjs-unit-test_skill

This skill helps you write, refactor, and maintain AngularJS unit tests with Jasmine and Jest across controllers, services, and directives.
  • TypeScript

3

GitHub Stars

3

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill greedychipmunk/agent-skills --skill angularjs-unit-test

  • INDEX.md6.6 KB
  • README.md10.4 KB
  • skill.md11.4 KB

Overview

This skill helps you write, refactor, and maintain unit tests for AngularJS applications using Jasmine and Jest. It focuses on practical patterns for testing controllers, services, filters, directives, HTTP interactions, promises, and scope behavior. The goal is fast, reliable tests with clear organization and measurable coverage.

How this skill works

The skill provides concrete test structures, templates, and patterns (AAA, mocking/spying, fixtures, edge-case testing, snapshot testing for Jest). It explains how to mock HTTP with $httpBackend or jest.mock(), handle $q and $timeout, and inject dependencies for isolated units. It also covers test runner setup (Karma for Jasmine, Jest configuration) and CI integration for automated coverage reporting.

When to use it

  • Adding unit tests to an existing AngularJS project
  • Writing or refactoring controller, service, directive, or filter tests
  • Mocking HTTP calls and async behavior in unit tests
  • Choosing between Jasmine (native AngularJS fit) and Jest (modern features, snapshots)
  • Integrating tests into CI/CD pipelines for coverage and regression checks

Best practices

  • Follow the AAA pattern: Arrange, Act, Assert for every test
  • Keep tests independent: use beforeEach/afterEach to reset state
  • Use realistic mocks and spies; avoid over-simplified stubs
  • Aim for broad coverage: happy paths, edge cases, and errors
  • Keep tests fast: prefer in-memory mocks and avoid real network or DB calls
  • Organize one test file per component and use meaningful test names

Example use cases

  • Unit-testing a controller that initializes scope and triggers events
  • Testing a service that performs $http calls with $httpBackend mocks
  • Validating directive compilation and DOM manipulation in isolation
  • Testing promise resolution and rejection using $q and $rootScope.$apply()
  • Migrating a test suite to Jest to add snapshot testing and faster mocks

FAQ

Use Jasmine with Karma when you want the established AngularJS testing experience and browser-based runs. Choose Jest when you need faster local feedback, built-in mocking, and snapshot testing, but ensure proper configuration for AngularJS modules.

How do I test async code that uses $q?

Create a deferred with $q.defer(), resolve or reject it, then call $rootScope.$apply() to flush the promise queue before asserting results. For Jest, use async/await or return the promise.

How do I mock HTTP requests in Jasmine and Jest?

In Jasmine use $httpBackend.expectGET/POST and $httpBackend.flush(). In Jest use jest.mock() to replace modules or mock fetch/axios and assert calls and responses.

What coverage target should I aim for?

Aim for 80%+ to balance safety and effort. Prioritize critical branches, error handling, and edge cases for higher value testing.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational