diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6db6c22..2662ca3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,9 @@ jobs: quality: name: Lint, Typecheck & Test runs-on: ubuntu-latest + # A builder that finishes its work and never exits would otherwise hold + # the runner for GitHub's six-hour default. + timeout-minutes: 15 steps: - uses: actions/checkout@v4 @@ -25,16 +28,25 @@ jobs: - name: Lint run: npm run lint + # The root tsconfig has "files": [] and only references, so a bare + # `tsc --noEmit` checks no files at all. Point it at the real configs. - name: Typecheck - run: npx tsc --noEmit + run: | + npx tsc --noEmit -p tsconfig.app.json + npx tsc --noEmit -p tsconfig.spec.json - name: Run unit tests (includes axe accessibility scans) run: npm test + # The only step that prerenders every route and enforces the bundle budget. + - name: Production build + run: npm run build + e2e-accessibility: name: E2E & Accessibility runs-on: ubuntu-latest needs: quality + timeout-minutes: 20 steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2241f50..a1276c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. +## 2026-11-21 - version 1.4.10 + +- **fix: CI's typecheck checked zero files.** It ran `npx tsc --noEmit` against the root `tsconfig.json`, which has `"files": []` and only project references, so plain `tsc` compiled nothing and passed. It now typechecks `tsconfig.app.json` and `tsconfig.spec.json` +- **CI runs the production build.** It's the only step that prerenders every route and enforces the bundle budget, and CI never ran it +- **Every CI job has a time limit.** I've seen `ng build` and `ng test` finish their work and then never exit; without `timeout-minutes` that holds a runner for GitHub's six-hour default +- **A spec reads the CI workflow** (`ci-workflow.spec.ts`), so none of the three gaps can come back quietly +- **An e2e test for the lesson nav** (`e2e/lesson-nav.spec.ts`). The unit specs drive a fake `IntersectionObserver`; this one scrolls a real page in Chromium +- **Corrected: the contact form's reset comment.** In 1.4.8 I wrote that `form.reset()` only re-rendered the OnPush contact form because a signal write sat next to it. A new spec shows it renders on its own: reactive form controls keep touched and status in signals, and `NgControlStatus` reads them in its host bindings +- **Angular guide, lesson 11: testing** (`/thoughts/angular-11-testing`). The live demo runs the real `notBlank` validator's tests in the page, with a switch that puts back the bug lesson 08 fixed. The lesson covers component specs, `HttpTestingController` with fake timers, `RouterTestingHarness`, marble tests, fitness tests and when e2e earns its place + ## 2026-11-21 - version 1.4.9 - **Every lesson has an "On this page" nav.** It sticks to the top while you read, jumps to a section (moving focus to its heading), and highlights the section in view with `aria-current="location"`. Smooth scrolling switches off under `prefers-reduced-motion`. The lessons had grown long enough that I kept losing my place in them diff --git a/e2e/lesson-nav.spec.ts b/e2e/lesson-nav.spec.ts new file mode 100644 index 0000000..aa5ff7f --- /dev/null +++ b/e2e/lesson-nav.spec.ts @@ -0,0 +1,27 @@ +import { expect, test } from '@playwright/test'; + +// The unit specs drive ScrollSpy with a fake IntersectionObserver, which can +// only prove the wiring. Whether the highlight follows real scrolling needs a +// real browser. +test.describe('lesson "On this page" nav', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/thoughts/angular-10-directives'); + await expect(page.getByRole('navigation', { name: 'On this page' })).toBeVisible(); + }); + + test('jumping to a section focuses its heading and marks it current', async ({ page }) => { + const nav = page.getByRole('navigation', { name: 'On this page' }); + await nav.getByRole('button', { name: 'Pitfalls' }).click(); + + await expect(page.locator('h2#pitfalls')).toBeFocused(); + await expect(nav.getByRole('button', { name: 'Pitfalls' })).toHaveAttribute('aria-current', 'location'); + }); + + test('the highlight follows the reader while scrolling', async ({ page }) => { + await page.locator('h2#expert').evaluate((heading) => heading.scrollIntoView({ block: 'start' })); + + const nav = page.getByRole('navigation', { name: 'On this page' }); + await expect(nav.getByRole('button', { name: 'Expert' })).toHaveAttribute('aria-current', 'location'); + await expect(nav.locator('[aria-current]')).toHaveCount(1); + }); +}); diff --git a/package-lock.json b/package-lock.json index e36aa50..5913851 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "angular-paul", - "version": "1.4.9", + "version": "1.4.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "angular-paul", - "version": "1.4.9", + "version": "1.4.10", "dependencies": { "@angular/common": "^21.2.0", "@angular/compiler": "^21.2.0", diff --git a/package.json b/package.json index 50c0c21..1e171bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-paul", - "version": "1.4.9", + "version": "1.4.10", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/src/app/apps/contact-app.spec.ts b/src/app/apps/contact-app.spec.ts index 952902f..7c27807 100644 --- a/src/app/apps/contact-app.spec.ts +++ b/src/app/apps/contact-app.spec.ts @@ -171,4 +171,21 @@ describe('ContactApp', () => { expect(component.form.value.email).toBeFalsy(); expect(component.form.value.message).toBeFalsy(); }); + + // [ng-11 testing] Pins a correction. Lesson 09 claimed reset() renders only + // because a signal write sits next to it. It renders on its own: each + // formControlName input carries NgControlStatus, whose host bindings read the + // control's touched and status signals. No detectChanges() here on purpose. + it('clears shown errors on reset() alone, with no other state change or event', async () => { + component.form.markAllAsTouched(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(nativeEl.querySelector('.contact-error-name')).toBeTruthy(); + + component.form.reset(); + await fixture.whenStable(); + + expect(nativeEl.querySelector('.contact-error-name')).toBeNull(); + expect(nativeEl.querySelector('.contact-error-email')).toBeNull(); + }); }); diff --git a/src/app/apps/contact-app.ts b/src/app/apps/contact-app.ts index e906010..405b26a 100644 --- a/src/app/apps/contact-app.ts +++ b/src/app/apps/contact-app.ts @@ -250,9 +250,12 @@ export class ContactApp { this.submissionStatus.set('pending'); // Simulate async submission - // [ng-09 change detection] form.reset() changes plain control state, - // which marks nothing for check. It renders because the signal write next - // to it does. Drop that write and the old errors stay on screen. + // [ng-09 change detection] form.reset() re-renders this OnPush view on its + // own. Controls keep touched and status in signals, and NgControlStatus + // (the directive behind ng-touched/ng-invalid, on every formControlName + // input) reads them in its host bindings. I first thought only the signal + // write below made it render; contact-app.spec.ts has the test that + // proved otherwise. setTimeout(() => { this.submissionStatus.set('success'); this.form.reset(); diff --git a/src/app/ci-workflow.spec.ts b/src/app/ci-workflow.spec.ts new file mode 100644 index 0000000..f41d36d --- /dev/null +++ b/src/app/ci-workflow.spec.ts @@ -0,0 +1,34 @@ +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +/** + * [ng-11 testing] CI is code too, and it can be green while checking nothing. + * These pin the three gaps I found in .github/workflows/ci.yml: a typecheck + * that covered no files, no production build, and no time limit on a job. + */ +const workflow = readFileSync(resolve(process.cwd(), '.github/workflows/ci.yml'), 'utf-8'); + +describe('[ng-11] CI workflow', () => { + it('the root tsconfig only holds references, so a bare `tsc --noEmit` checks no files', () => { + const root = readFileSync(resolve(process.cwd(), 'tsconfig.json'), 'utf-8'); + expect(root).toMatch(/"files":\s*\[\]/); + }); + + it('typechecks the app and the specs through their own tsconfigs', () => { + expect(workflow).toMatch(/tsc --noEmit -p tsconfig\.app\.json/); + expect(workflow).toMatch(/tsc --noEmit -p tsconfig\.spec\.json/); + }); + + it('runs the production build, which is the only step that prerenders and enforces budgets', () => { + expect(workflow).toMatch(/run: npm run build/); + }); + + it('gives every job a time limit, so a hung builder fails in minutes rather than six hours', () => { + const jobs = workflow + .slice(workflow.indexOf('\njobs:\n')) + .split(/\n {2}(?=[\w-]+:\n)/) + .slice(1); + expect(jobs.map((job) => job.slice(0, job.indexOf(':')))).toEqual(['quality', 'e2e-accessibility']); + for (const job of jobs) expect(job).toMatch(/\n {4}timeout-minutes: \d+/); + }); +}); diff --git a/src/app/thoughts-content/lessons/lesson-11-testing.spec.ts b/src/app/thoughts-content/lessons/lesson-11-testing.spec.ts new file mode 100644 index 0000000..17dc886 --- /dev/null +++ b/src/app/thoughts-content/lessons/lesson-11-testing.spec.ts @@ -0,0 +1,58 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import * as axeMatchers from 'vitest-axe/matchers'; +import { axe } from '../../../test/a11y'; +import { LESSON_PAGES } from './lessons'; +import { Lesson11Testing } from './lesson-11-testing'; + +expect.extend(axeMatchers); + +describe('Lesson11Testing', () => { + let fixture: ComponentFixture; + let el: HTMLElement; + + const summary = () => el.querySelector('#demo-test-summary')?.textContent?.trim(); + const click = async (selector: string) => { + el.querySelector(selector)!.click(); + await fixture.whenStable(); + }; + + beforeEach(async () => { + await TestBed.configureTestingModule({ imports: [Lesson11Testing] }).compileComponents(); + fixture = TestBed.createComponent(Lesson11Testing); + await fixture.whenStable(); + el = fixture.nativeElement as HTMLElement; + }); + + it('is registered as the lesson page for its thought', () => { + expect(LESSON_PAGES['angular-11-testing']).toBeDefined(); + }); + + it('teaches at three levels, then pitfalls and interview questions', () => { + const headings = [...el.querySelectorAll('h2')].map((h) => h.textContent?.trim()); + expect(headings).toEqual( + expect.arrayContaining(['Simple', 'Intermediate', 'Expert', 'Pitfalls', 'Interview questions']), + ); + }); + + it("runs the real notBlank validator's tests in the page, and they pass", async () => { + await click('#demo-run-tests'); + expect(summary()).toBe('3 passed'); + }); + + it('putting the lesson 08 bug back makes exactly the whitespace test fail', async () => { + await click('#demo-break'); + await click('#demo-run-tests'); + + expect(summary()).toBe('1 failed, 2 passed'); + const failures = [...el.querySelectorAll('.demo-test-result')].filter((li) => + li.textContent?.includes('FAIL'), + ); + expect(failures.map((li) => li.textContent)).toEqual([expect.stringContaining('only spaces')]); + }); + + it('has no axe violations, with results showing', async () => { + await click('#demo-break'); + await click('#demo-run-tests'); + expect(await axe(el)).toHaveNoViolations(); + }); +}); diff --git a/src/app/thoughts-content/lessons/lesson-11-testing.ts b/src/app/thoughts-content/lessons/lesson-11-testing.ts new file mode 100644 index 0000000..bcc0df2 --- /dev/null +++ b/src/app/thoughts-content/lessons/lesson-11-testing.ts @@ -0,0 +1,311 @@ +import { ChangeDetectionStrategy, Component, signal } from '@angular/core'; +import type { AbstractControl, ValidationErrors } from '@angular/forms'; +import { notBlank } from '../../shared/validators'; +import { Callout } from './callout'; +import { CodeBlock } from './code-block'; +import { InterviewQuestions } from './interview-questions'; +import { Lesson } from './lesson'; +import { LessonDemo } from './lesson-demo'; +import { LessonSection } from './lesson-section'; + +type Validator = (control: AbstractControl) => ValidationErrors | null; + +// The bug lesson 08 fixed: Validators.required only rejects ''. +const notBlankBeforeLesson08: Validator = (control) => + control.value === '' ? { blank: true } : null; + +const NOT_BLANK_CASES = [ + { name: 'rejects an empty message', value: '', blank: true }, + { name: 'rejects a message of only spaces', value: ' ', blank: true }, + { name: 'accepts real text', value: 'hello', blank: false }, +]; + +interface TestResult { + name: string; + passed: boolean; + detail: string; +} + +@Component({ + selector: 'app-lesson-11-testing', + changeDetection: ChangeDetectionStrategy.OnPush, + imports: [Lesson, LessonSection, LessonDemo, CodeBlock, Callout, InterviewQuestions], + template: ` + +

Simple

+

+ A good component test acts like a user and checks what a user would see. It sets inputs, + clicks things, types, and then reads the DOM. It doesn't call private methods or inspect + fields, because those can change without anything visible changing. +

+

+ Angular 21 runs unit tests on Vitest through ng test. + TestBed builds a small Angular environment for each test. + fixture.whenStable() waits for the zoneless scheduler to render. Every + component spec on this site ends with an axe scan, so accessibility regressions fail the + build like any other bug. +

+ +

+ The smallest tests are for plain functions. Below, the real notBlank + validator from lesson 08 runs its tests in this page. Flip the switch to put back the bug + that lesson fixed, and see which test catches it. +

+ +
+ + + +
+
    + @for (result of results(); track result.name) { +
  • + {{ result.passed ? '✓ PASS' : '✗ FAIL' }} {{ result.name }} + @if (result.detail) { + {{ result.detail }} + } +
  • + } +
+

{{ summary() }}

+
+ + +

Intermediate

+

+ Replace what you don't own. Give the TestBed different providers and read + them back with TestBed.inject. For HTTP, + provideHttpClientTesting() swaps the backend for + HttpTestingController. You assert on each request and decide what comes back. + Combine it with fake timers and a retry with backoff becomes a test that runs in + milliseconds. +

+ +

+ Routing. RouterTestingHarness navigates a real router + configuration and hands back the routed component. This site's spec uses the actual + appConfig, so it tests the wiring that ships, not a copy. + Inputs. Set them with fixture.componentRef.setInput(), which + goes through the same path as a parent template and works with OnPush. +

+ +

Expert

+

+ Marble tests. RxJS's TestScheduler runs observables in virtual + time. A 100ms delay costs nothing, and the order of arrivals is exact. Lesson 06's race + between switchMap and mergeMap is proven this way. +

+ +

+ Fitness tests. Some rules span the whole codebase: features stay lazy, + every component is OnPush. A spec that reads the source tree turns those rules into failures + with file names. The same idea caught three gaps in this site's CI config. The typecheck ran + tsc against a root tsconfig with no files, so it checked nothing. The + production build never ran. And no job had a time limit. +

+ +

+ When to go end to end. jsdom has no layout and no + IntersectionObserver. The lesson nav's unit tests use a fake observer, so they + prove the wiring and nothing more. A Playwright test in e2e/ scrolls a real + page in Chromium. Keep e2e tests few and focused on what only a browser can show: they're + slow, and a flaky one teaches people to ignore red. +

+ +

+ Angular CDK's component harnesses wrap a component's DOM in a small API + (await select.open()). That keeps specs stable when the markup changes, and + the same harness works in unit and e2e tests. This site has no CDK components, so it + doesn't use them, but in a Material codebase you'd reach for them first. +

+
+ +

Pitfalls

+ +

+ A green summary is not an exit code. Once, this site's test run printed + "426 passed" and then never exited. The cause was an esbuild context left open by two + components with identical inline styles. CI only knows the exit code. Check it, and give + jobs a timeout. +

+
+ +

+ A test you've never seen fail proves nothing. Write it first, watch it + fail for the right reason, then make it pass. My first CI spec split the YAML wrong. It + was failing on the on: block, not on the jobs it claimed to check. +

+
+ +

+ Believing a comment over a test. In lesson 09 I wrote that the contact + form's reset() only re-rendered because a signal write happened next to it. A + spec in this lesson resets the form with no other change and no + detectChanges(), and the errors still clear. Reactive form controls keep + touched and status in signals, and NgControlStatus (the directive that adds + ng-touched) reads them in its host bindings. The comment is corrected now, + and the test keeps it honest. +

+
+ +

+ Fake timers and whenStable(). With + vi.useFakeTimers(), the zoneless scheduler waits on a timer that never fires, + so whenStable() hangs. Drive it with + vi.advanceTimersByTimeAsync() instead. +

+
+ +

+ Setting a field, then detectChanges(). Under OnPush the view + isn't dirty, so nothing renders. Use setInput, DOM events or signals (lesson + 09). +

+
+ +

Interview questions

+ +
+ `, + styles: ` + .demo-test-results { + margin: 8px 0; + padding-left: 0; + list-style: none; + font-family: var(--font-mono, ui-monospace, monospace); + font-size: 12px; + } + .demo-test-result--fail { + font-weight: 600; + } + .demo-test-detail { + display: block; + padding-left: 2ch; + font-weight: normal; + } + `, +}) +export class Lesson11Testing { + protected readonly broken = signal(false); + protected readonly results = signal([]); + protected readonly summary = signal(''); + + protected run(): void { + const validator: Validator = this.broken() ? notBlankBeforeLesson08 : notBlank; + const results = NOT_BLANK_CASES.map(({ name, value, blank }) => { + const errors = validator({ value } as AbstractControl); + const passed = (errors?.['blank'] === true) === blank; + const expected = blank ? '{ blank: true }' : 'null'; + return { + name, + passed, + detail: passed ? '' : `expected ${expected}, got ${JSON.stringify(errors)}`, + }; + }); + const failed = results.filter((result) => !result.passed).length; + const passed = results.length - failed; + this.results.set(results); + this.summary.set(failed ? `${failed} failed, ${passed} passed` : `${passed} passed`); + } + + protected readonly snippets = { + component: `it('submitting an invalid form shows every error, focuses the first bad field, and sends nothing', async () => { + component.form.controls.name.setValue('Paul'); + (nativeEl.querySelector('.contact-submit') as HTMLButtonElement).click(); + await fixture.whenStable(); + + expect(nativeEl.querySelector('.contact-error-email')).toBeTruthy(); + expect(nativeEl.querySelector('.contact-error-message')).toBeTruthy(); + expect(nativeEl.querySelector('.contact-error-name')).toBeNull(); + expect(document.activeElement?.id).toBe('contact-email'); + expect(component.submissionStatus()).toBe('idle'); +}); + +it('has no axe violations while errors are showing', async () => { + component.form.markAllAsTouched(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(await axe(nativeEl)).toHaveNoViolations(); +});`, + validator: `it('rejects a message of only spaces', () => { + expect(notBlank(new FormControl(' ', { nonNullable: true }))).toEqual({ blank: true }); +});`, + http: `beforeEach(() => { + vi.useFakeTimers(); + TestBed.configureTestingModule({ + providers: [ + provideHttpClient(withInterceptors([retryTransientErrors])), + provideHttpClientTesting(), + ], + }); + http = TestBed.inject(HttpClient); + backend = TestBed.inject(HttpTestingController); +}); + +afterEach(() => backend.verify()); // fails on any request nobody answered + +it('retries a GET that hit a 5xx, after a backoff delay', () => { + get(); + backend.expectOne('/repos').flush('down', { status: 503, statusText: 'Service Unavailable' }); + + backend.expectNone('/repos'); // not yet: it's waiting + vi.advanceTimersByTime(500); + backend.expectOne('/repos').flush(['angular-paul']); + + expect(result).toEqual(['angular-paul']); +});`, + marbles: `it('with switchMap, a new query cancels the one in flight', () => { + scheduler.run(({ hot, expectObservable }) => { + const typed = hot('a 9ms b', { a: 'a', b: 'ab' }); + expectObservable(typed.pipe(searchAsYouType('switchMap', search))).toBe('30ms x', { + x: 'results for ab', + }); + }); +});`, + fitness: `const workflow = readFileSync(resolve(process.cwd(), '.github/workflows/ci.yml'), 'utf-8'); + +it('typechecks the app and the specs through their own tsconfigs', () => { + expect(workflow).toMatch(/tsc --noEmit -p tsconfig\\.app\\.json/); + expect(workflow).toMatch(/tsc --noEmit -p tsconfig\\.spec\\.json/); +}); + +it('runs the production build', () => { + expect(workflow).toMatch(/run: npm run build/); +});`, + }; + + protected readonly interview = [ + { + q: 'What do you test in an Angular component?', + a: 'Its behaviour through its public surface: what renders for given inputs, what happens on clicks and typing, which outputs it emits, and what it asks its services to do. Not private methods or internal fields, because those tests break on refactors that change nothing a user can see. I also run axe in component specs so accessibility regressions fail like any other bug.', + }, + { + q: 'How do you test a component that makes HTTP calls?', + a: 'Provide provideHttpClient() and provideHttpClientTesting(), then inject HttpTestingController. Trigger the behaviour, use expectOne to assert the request, flush a response or an error, and assert on the rendered result. verify() in afterEach fails the test if any request was left unanswered. For retries and debouncing, add fake timers so the test controls time.', + }, + { + q: 'Unit, integration or e2e?', + a: 'Mostly fast unit and component tests, because they pin behaviour cheaply and run on every save. Integration-style specs use the real config, for example routing tested against appConfig. A few e2e tests cover what needs a real browser: layout, scrolling, IntersectionObserver, and the critical user journeys. E2e tests are slow and more prone to flakiness, so each one should earn its place.', + }, + { + q: 'How do you test RxJS code?', + a: 'With marble tests on the RxJS TestScheduler. Inside scheduler.run(), every timer uses virtual time, so delays, debounces and races are deterministic and instant. You describe input streams as marble strings and assert the output against an expected one. For simple cases, subscribing and asserting after fake timers is fine too.', + }, + { + q: 'Karma and Jasmine vs Jest vs Vitest?', + a: 'Karma with Jasmine was the Angular default for years and ran tests in a real browser. New Angular 21 projects default to Vitest through the @angular/build:unit-test builder, which runs in jsdom with an optional browser mode. Jest was a common community choice in between. The TestBed API is the same in all of them, so most specs move between runners with little change.', + }, + { + q: 'Tell me about a test that caught something.', + a: 'On my site, a fitness test that reads the CI workflow showed that its typecheck step checked zero files. The root tsconfig only has project references, so plain tsc compiles nothing. CI had been green the whole time. The spec now requires the real tsconfigs, a production build, and a timeout on every job.', + }, + ]; +} diff --git a/src/app/thoughts-content/lessons/lessons.ts b/src/app/thoughts-content/lessons/lessons.ts index 3d4c894..5357ceb 100644 --- a/src/app/thoughts-content/lessons/lessons.ts +++ b/src/app/thoughts-content/lessons/lessons.ts @@ -22,4 +22,5 @@ export const LESSON_PAGES: Record Promise>> = { 'angular-09-change-detection': () => import('./lesson-09-change-detection').then((m) => m.Lesson09ChangeDetection), 'angular-10-directives': () => import('./lesson-10-directives').then((m) => m.Lesson10Directives), + 'angular-11-testing': () => import('./lesson-11-testing').then((m) => m.Lesson11Testing), }; diff --git a/src/app/thoughts-content/thoughts-bodies.ts b/src/app/thoughts-content/thoughts-bodies.ts index 07944e0..1396ff7 100644 --- a/src/app/thoughts-content/thoughts-bodies.ts +++ b/src/app/thoughts-content/thoughts-bodies.ts @@ -268,10 +268,13 @@ Wiring that up showed how much of the routing had been done by hand. The cards w 'angular-08-forms': `I opened the contact form to use as this lesson's example and found three things wrong with it. A message of nothing but spaces passed validation, because Validators.required only rejects an empty string. Send stayed greyed out until everything was valid, and nothing said why. And the error messages were just text sitting near the fields, with nothing telling a screen reader which field they belonged to. All three are fixed now. Send stays enabled; pressing it shows every problem and puts focus on the first one. The demo below covers what the contact form doesn't need: a rule that spans two fields, and a list of fields that grows and shrinks.`, - 'angular-09-change-detection': `Until this lesson, none of the 35 components on this site set a change detection strategy, so every one of them was checked on every pass. Before switching them all to OnPush, I went through each looking for state that changes outside signals and template events, since that's the state OnPush silently stops rendering. There was none, which says more about the earlier lessons moving everything to signals than about luck. The closest call is the contact form's reset, which only shows up because a signal write sits next to it. + 'angular-09-change-detection': `Until this lesson, none of the 35 components on this site set a change detection strategy, so every one of them was checked on every pass. Before switching them all to OnPush, I went through each looking for state that changes outside signals and template events, since that's the state OnPush silently stops rendering. There was none, which says more about the earlier lessons moving everything to signals than about luck. I flagged the contact form's reset as a close call, thinking it only rendered because a signal write sat next to it. Lesson 11 has the test that proved me wrong: reactive form controls keep their touched and status state in signals, and the directive behind ng-touched reads them. A test in architecture.spec.ts now fails on any component that doesn't choose a strategy. The demo below sets an Eager child next to an OnPush one and passes both the same object, so you can watch mutation leave one of them behind.`, 'angular-10-directives': `By lesson nine the pages were long enough that I kept losing my place in them, so every lesson now has an "On this page" nav that sticks to the top and highlights the section you're in. It comes from two small directives, and they cover most of what directives are for. One gives every heading an id and registers it. The other watches those headings and reports which one is in view. The lesson component picks that up as a host directive rather than anyone remembering to add an attribute. The demos below cover the parts the nav didn't need: a structural directive, and an input renamed through hostDirectives.`, + 'angular-11-testing': `I wrote a spec that reads this site's CI workflow, mostly as an example of a fitness test. It failed straight away. The typecheck step ran tsc against a root tsconfig that only holds project references, so it had been checking zero files while showing green. CI also never ran the production build, and no job had a time limit. Earlier in this series I had a test run print "426 passed" and then never exit, so that last one wasn't theoretical. + +The same lesson caught me out a second time. A test I wrote to pin a claim from lesson 09 passed when the claim said it shouldn't, and the claim turned out to be wrong. The demo below runs the real contact form validator's tests in the page, with a switch that puts back the bug lesson 08 fixed.`, }; diff --git a/src/app/thoughts-content/thoughts-data.ts b/src/app/thoughts-content/thoughts-data.ts index bcf5c24..8ef4ccd 100644 --- a/src/app/thoughts-content/thoughts-data.ts +++ b/src/app/thoughts-content/thoughts-data.ts @@ -278,4 +278,13 @@ export const THOUGHTS: ThoughtEntry[] = [ tags: ['angular-guide', 'directives', 'angular'], relatedApp: 'readme', }, + { + slug: 'angular-11-testing', + title: 'Angular 11: Testing', + date: '2026-11-21', + summary: + 'Component specs with TestBed and axe, HttpTestingController with fake timers, marble tests, fitness tests and where e2e earns its place. Built while finding out my CI typecheck had been checking zero files.', + tags: ['angular-guide', 'testing', 'angular'], + relatedApp: 'contact', + }, ];