Tests should exercise the actual production code and fail with clear, actionable messages when something breaks.
instanceof to verify a class’s prototype chain rather than comparing constructor.name, and isolate async setup (e.g., dynamic imports) in a before()/beforeEach() hook so a load failure surfaces as one clear failure instead of cascading as undefined across unrelated assertions later in the suite.mock.calls[0] directly—if the mock was never called, this throws an opaque undefined is not iterable error that obscures the real failure. Use expect(fn).toHaveBeenCalledWith(...) instead, which reports a precise, readable diff of expected vs. actual arguments.Example:
// Bad: re-implemented logic + brittle destructure/equality
function stripReasoningContent(body) { /* copy of prod code */ }
const [url, init] = fetch.mock.calls[0]; // throws if fetch wasn't called
expect(url).toBe(expected);
// Good: real implementation + clear failure message
import { stripReasoningContent } from "../../open-sse/executors/kimchi.js";
expect(fetch).toHaveBeenCalledWith(expectedUrl, expect.objectContaining({ body: expectedBody }));
expect(instance instanceof DefaultExecutor).toBe(true);