Index of every page on this site: llms.txt
All skills
marmicode avatar

/angular-testing

@fa09f8d
by marmicodemarmicode/skills17 stars
Run it yourself

Writes, fixes and reviews Angular tests following the Pragmatic Angular Testing approach — fakes over mocks, real collaborators by default, components tested through the DOM rather than through fixtures. Targets Vitest (Browser Mode preferred, jsdom and happy-dom supported) and also applies to Jest, Jasmine/Karma and Angular Testing Library projects, including migrating them to Vitest. Use whenever adding, editing, reviewing or debugging unit tests in an Angular project — *.spec.ts files, TestBed, components, services (`@Service` or `@Injectable`), signals, guards, routing, and timers — including when tests are written as part of a feature or bug fix, when replacing mocks or spies with fakes, when declaring or faking a service, and when fixing slow or flaky tests. Prefer this over general Angular skills for anything test-related. Not for Playwright or Cypress end-to-end tests.

Use this Skill: https://skilld.dev/gh/marmicode/skills/angular-testing

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesemulated-dom.md

≈673 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Emulated DOM (jsdom, happy-dom)

Use this only when the project has no Browser Mode project. If the Vitest config has one, component tests belong there (*.browser.spec.ts and page locators), including shallow tests. Everything else in this skill still applies.

Contents

  1. Limits
  2. Mounting
  3. Querying and Asserting
  4. Interacting
  5. Migrating to Browser Mode

Limits

  • vitest/browser (page, expect.element) can't be imported.
  • There is no layout, CSS, or actionability: a test can click a hidden or covered button. UI bugs that only show in a real browser go unnoticed.
  • Some browser APIs are missing or behave differently (e.g. requestAnimationFrame is simulated).

Mounting

Same as in Browser Mode: TestBed.createComponent(Component, { bindings }), fixture ignored, fakes provided through TestBed.

Querying and Asserting

Query with screen from @testing-library/dom, not @testing-library/angular: Angular Testing Library's async utilities (findBy*, waitFor) trigger change detection, which hides synchronization bugs that would break the app once zoneless.

import { screen } from '@testing-library/dom';

await expect
  .poll(() => screen.queryAllByRole('heading').map((el) => el.textContent))
  .toEqual(['Burger']);
  • Use the same query priority as in Browser Mode: role, label, placeholder, text, alt or title, test id.
  • findBy* queries from @testing-library/dom also retry without triggering change detection.
  • toHaveTextContent(), toBeDisabled(), etc. require @testing-library/jest-dom in the test setup file.
  • Don't use fixture.detectChanges() or fixture.whenStable(): retry the assertion instead.

Interacting

import { userEvent } from '@testing-library/user-event';

await userEvent.type(screen.getByLabelText('Keywords'), 'Burger');
await userEvent.click(screen.getByRole('button', { name: 'ADD' }));

With fake timers in manual mode, let userEvent advance them:

const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTimeAsync });

await user.type(screen.getByLabelText('Keywords'), 'Burger');

Migrating to Browser Mode

Prefer Browser Mode for component tests: see setup.md. Migrate progressively:

  1. Run the existing tests in the browser ("partial" Browser Mode).
  2. Replace the @testing-library/user-event import with import { userEvent } from 'vitest/browser' to route interactions through the browser provider.
  3. Replace DOM queries and assertions with page locators and expect.element in new or flaky tests.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts11d3 checks · Risk SAFE
  • Gen Agent Trust Hub11d

    The skill provides comprehensive guidelines and examples for writing Angular tests using Vitest and other industry-standard tools. It promotes testing best practices like using fakes and browser-mode integration testing. No malicious patterns, obfuscation, or security risks were identified.

  • Socket11d

    No alerts

  • Snyk11d

    Risk: LOW · No issues

Signed by skilld at fa09f8d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 weeks ago

README badge

README badge for marmicode/skills/angular-testing