testing-patterns

Provide testing patterns for Nuclai frontend monorepo Angular Jest Vitest Svelte React components and mocking strategies.

56|18|Updated Apr 26, 2022
One-click install
npx skills add https://github.com/nuclia/frontend --skill testing-patterns-nuclia
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/nuclia/frontend/tree/main/.claude/skills/testing-patterns
Command: npx skills add https://github.com/nuclia/frontend --skill testing-patterns-nuclia

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and best practices for testing within the Nuclia frontend monorepo, ensuring robust and maintainable code.

Core Features & Use Cases

  • Unified Testing Approach: Covers Jest for Angular and Vitest for Svelte/React projects.
  • Component Testing: Demonstrates patterns for testing standalone and legacy Angular components, including signal inputs and OnPush strategy.
  • Service & Utility Testing: Guides on isolating and testing services and utilities effectively.
  • Mocking Strategies: Details the use of ng-mocks for Angular and Vitest's mocking capabilities.
  • Use Case: When writing a new spec file for an Angular component, you can consult this Skill to ensure you're using the correct TestBed configuration, MockProvider for services, and fixture.detectChanges() for OnPush components.

Quick Start

Use the testing-patterns skill to understand how to mock Angular services in your spec files.

Frequently Asked Questions about testing-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Angular components with OnPush change detection and signal inputs?

Testing Angular components with OnPush change detection and signal inputs requires calling fixture.detectChanges() manually. You should configure TestBed properly and use MockProvider to isolate services within your spec files.

What is the best way to mock Angular services in a Jest spec file?

The best way to mock Angular services in a Jest spec file is using ng-mocks. This library provides MockProvider and MockBuilder utilities to isolate dependencies effectively when configuring your TestBed setup.

Does Vitest work for testing Svelte and React components in a monorepo?

Vitest works effectively for testing Svelte and React components in a monorepo. It provides specific environments and mocking capabilities tailored for unit and integration testing across these frontend frameworks.

How do I configure jest-preset-angular for testing standalone Angular components?

Configuring jest-preset-angular for testing standalone Angular components involves setting up TestBed with the correct imports. You can leverage ng-mocks to handle legacy and standalone component isolation within your Jest testing environment.

Why do I need to call fixture.detectChanges when testing OnPush components?

You need to call fixture.detectChanges when testing OnPush components because change detection is not triggered automatically. This manual call ensures the DOM updates correctly after setting signal inputs or modifying component properties.

Can I use the same testing patterns for both Jest and Vitest in a frontend monorepo?

You cannot use identical patterns because Jest is configured with jest-preset-angular for Angular apps, while Vitest handles Svelte and React. However, similar isolation and mocking strategies apply across both testing frameworks.