Community编程与开发github.com

analogjs/angular-testing

使用 Vitest 或 Jasmine 与 TestBed 及现代测试模式,为 Angular v20+ 应用编写单元测试和集成测试。适用于测试包含信号的组件、OnPush 变更检测、使用 inject() 的服务以及 HTTP 交互。触发条件包括创建测试、测试基于信号的组件、模拟依赖或设置测试基础设施。不适用于使用 Cypress 或 Playwright 进行端到端测试,也不适用于测试非 Angular 的 JavaScript/TypeScript 代码。

angular-testing 是什么?

此技能面向 Angular v20+ 开发者,提供了基于 Vitest 或 Jasmine 结合 Angular TestBed 编写单元测试和集成测试的全面指南。它涵盖了现代 Angular 测试模式,特别针对信号驱动的组件、OnPush 变更检测策略、使用 inject() 函数的服务以及 HTTP 交互进行测试。该技能详细指导了如何设置测试基础设施、创建测试文件、模拟服务依赖以及验证交互,确保测试高效且可靠。支持在 Angular CLI 项目以及 Nx 和 AnalogJS 等现代构建工具中使用。需要注意的是,该技能不适用于 Cypress 或 Playwright 的端到端(E2E)测试,也不适用于非 Angular 的 JavaScript/TypeScript 代码的测试。通过遵循该技能的最佳实践和示例,开发者能够轻松地为其 Angular 应用构建健壮的测试套件,充分利用最新特性并维护高质量的代码库。

兼容平台~Claude Code~Codex CLI~Cursor
Part ofReact
npx skills add https://github.com/analogjs/angular-skills/tree/main/skills/angular-testing

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

angular-testing 是做什么的?

为 Angular v20+ 应用编写使用 Vitest 或 Jasmine 与 TestBed 及现代测试模式的单元测试和集成测试。用于测试包含信号的组件、OnPush 变更检测、使用 inject() 的服务以及 HTTP 交互。触发条件包括创建测试、测试基于信号的组件、模拟依赖或设置测试基础设施。不适用于使用 Cypress 或 Playwright 进行端到端测试,也不适用于测试非 Angular 的 JavaScript/TypeScript 代码。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

analogjs/angular-component

Create modern Angular standalone components following v20+ best practices. Use for building UI components with signal-based inputs/outputs, OnPush change detection, host bindings, content projection, and lifecycle hooks. Triggers on component creation, refactoring class-based inputs to signals, adding host bindings, or implementing accessible interactive components.

analogjs/angular-di

Implement dependency injection in Angular v20+ using inject(), injection tokens, and provider configuration. Use for service architecture, providing dependencies at different levels, creating injectable tokens, and managing singleton vs scoped services. Triggers on service creation, configuring providers, using injection tokens, or understanding DI hierarchy.

analogjs/angular-directives

Create custom directives in Angular v20+ for DOM manipulation and behavior extension. Use for attribute directives that modify element behavior/appearance, structural directives for portals/overlays, and host directives for composition. Triggers on creating reusable DOM behaviors, extending element functionality, or composing behaviors across components. Note - use native @if/@for/@switch for control flow, not custom structural directives.

analogjs/angular-forms

Build signal-based forms in Angular v21+ using the new Signal Forms API. Use for form creation with automatic two-way binding, schema-based validation, field state management, and dynamic forms. Triggers on form implementation, adding validation, creating multi-step forms, or building forms with conditional fields. Signal Forms are experimental but recommended for new Angular projects. Don't use for template-driven forms without signals or third-party form libraries like Formly or ngx-formly.

analogjs/angular-http

Implement HTTP data fetching in Angular v20+ using resource(), httpResource(), and HttpClient. Use for API calls, data loading with signals, request/response handling, and interceptors. Triggers on data fetching, API integration, loading states, error handling, or converting Observable-based HTTP to signal-based patterns.

analogjs/angular-routing

Implement routing in Angular v20+ applications with lazy loading, functional guards, resolvers, and route parameters. Use for navigation setup, protected routes, route-based data loading, and nested routing. Triggers on route configuration, adding authentication guards, implementing lazy loading, or reading route parameters with signals.

analogjs/angular-signals

Implement signal-based reactive state management in Angular v20+. Use for creating reactive state with signal(), derived state with computed(), dependent state with linkedSignal(), and side effects with effect(). Triggers on state management questions, converting from BehaviorSubject/Observable patterns to signals, or implementing reactive data flows.

analogjs/angular-ssr

Implement server-side rendering and hydration in Angular v20+ using @angular/ssr. Use for SSR setup, hydration strategies, prerendering static pages, and handling browser-only APIs. Triggers on SSR configuration, fixing hydration mismatches, prerendering routes, or making code SSR-compatible.

analogjs/angular-tooling

Use Angular CLI and development tools effectively in Angular v20+ projects. Use for project setup, code generation, building, testing, and configuration. Triggers on creating new projects, generating components/services/modules, configuring builds, running tests, or optimizing production builds. Don't use for Nx workspace commands, custom Webpack configurations, or non-Angular CLI build systems like Vite standalone or esbuild direct usage.

相关技能