testing-with-nullableslisted
Install: claude install-skill msewell/agent-stuff
# Testing With Nullables
## Core concept
Nullables are production classes with an infrastructure "off switch." Each infrastructure class provides two factories:
- `create()` — production instance with real I/O
- `createNull()` — same class, same code paths, but I/O suppressed at the third-party boundary
Tests exercise real production code. Only the lowest-level third-party calls are stubbed.
```typescript
class CommandLine {
private constructor(private stdout: WritableStream, private _args: string[]) {}
static create(): CommandLine {
return new CommandLine(process.stdout, process.argv.slice(2));
}
static createNull(options?: { args?: string[] }): CommandLine {
return new CommandLine(new NullWritableStream(), options?.args ?? []);
}
write(text: string): void { this.stdout.write(text); }
args(): string[] { return this._args; }
}
```
## Workflow: Making a dependency testable with Nullables
1. **Identify the infrastructure boundary.** Find the class that talks to an external system (HTTP, file system, database, stdout).
2. **Create an Infrastructure Wrapper** if one doesn't exist. One wrapper per external system. Translate between external formats and domain types.
3. **Add an Embedded Stub.** Stub the *third-party code* (not yours) with a minimal implementation covering only the methods your code calls. Keep it in the same file.
4. **Add `createNull()`** factory that injects the embedded stub instead of the real third-party dependency. Both factor