pickstack

Angular + Vitest

Vite-native test runner, with a sample counter component test. This page shows exactly what pickstack adds to a Angular project for Vitest: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework angular --modules vitest --yes
Customize in the configurator

Packages it adds

PackageVersionType
jsdom^31.0.1dev
vitest^5.1.1dev

New files

src/app/components/counter/counter.spec.ts
import { TestBed } from "@angular/core/testing";
import { Counter } from "./counter";

describe("Counter", () => {
  it("increments when +1 is clicked", async () => {
    const fixture = TestBed.createComponent(Counter);
    await fixture.whenStable();
    const element = fixture.nativeElement as HTMLElement;

    const plus = [...element.querySelectorAll("button")].find(
      (b) => b.textContent?.trim() === "+1",
    );
    plus?.click();
    await fixture.whenStable();

    expect(element.querySelector("p")?.textContent?.trim()).toBe("1");
  });
});
tsconfig.spec.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "types": ["vitest/globals"]
  },
  "include": ["src/**/*.d.ts", "src/**/*.spec.ts"]
}

Changes to existing files

angular.json (changed)
⋯ 61 unchanged lines             }           },           "defaultConfiguration": "development"+        },+        "test": {+          "builder": "@angular/build:unit-test"         }       }     }⋯ 3 unchanged lines
src/app/pages/about/about.html (changed)
 <section class="page">   <h1 class="title">About</h1>+  <p class="text">Built with Angular 22, TypeScript, Vitest.</p>−  <p class="text">Built with Angular 22, TypeScript.</p> </section>  
tsconfig.json (changed)
⋯ 22 unchanged lines   "references": [     {       "path": "./tsconfig.app.json"+    },+    {+      "path": "./tsconfig.spec.json"     }   ] }⋯ 1 unchanged lines

Project files

Related templates