denoland/deno · error · AssertionError

Missing snapshot: ${name}

Error message

Missing snapshot: ${name}

What it means

AssertionError from assertSnapshot() (cli/js/40_test_snapshot.js): the snapshot file exists, but it has no entry for this snapshot's key. Keys are `${testName} ${count}`, derived from the full nested test name and a per-test counter of assertSnapshot calls — so adding, renaming, or reordering snapshot calls invalidates keys.

Source

Thrown at cli/js/40_test_snapshot.js:358

  const expectedSnapshot = MapPrototypeGet(context.currentValues, name);

  if (getIsUpdateMode()) {
    if (actualSnapshot !== expectedSnapshot) {
      MapPrototypeSet(context.updatedValues, name, actualSnapshot);
      if (!ArrayPrototypeIncludes(context.updatedNames, name)) {
        ArrayPrototypePush(context.updatedNames, name);
      }
    }
    return;
  }

  if (!context.fileExists) {
    throw new AssertionError(
      getErrorMessage("Missing snapshot file.", options),
    );
  }
  if (expectedSnapshot === undefined) {
    throw new AssertionError(
      getErrorMessage(`Missing snapshot: ${name}`, options),
    );
  }
  if (actualSnapshot === expectedSnapshot) {
    return;
  }
  throw new AssertionError(
    getErrorMessage(
      getSnapshotNotMatchMessage(actualSnapshot, expectedSnapshot),
      options,
    ),
  );
}

function buildSnapshotFileContent(names, getValue) {
  const buf = ["export const snapshot = {};"];
  for (const name of new SafeArrayIterator(names)) {
    const value = getValue(name);

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Run `deno test --update-snapshots` to record the new key, then review and commit the diff
  2. If tests were renamed, expect all their snapshot entries to move — update and commit
  3. For order/branch-dependent assertions, pass an explicit stable { name: "..." } option so keys don't depend on call order

Example fix

// before
Deno.test("formats config", async (t) => {
  await t.assertSnapshot(fmt(a));
  await t.assertSnapshot(fmt(b)); // newly added → Missing snapshot: formats config 2
});

// after — record it once, commit the snapshot file
deno test --update-snapshots
Defensive patterns

Strategy: validation

Validate before calling

// keep keys stable across refactors by naming snapshots explicitly
await t.step("formats config", async () => {
  await t.assertSnapshot(a, { name: "config-a" });
  await t.assertSnapshot(b, { name: "config-b" });
});

Prevention

When it happens

Trigger: Adding a new t.assertSnapshot() call to an existing test; renaming a test (or any parent step name) so the stored key no longer matches; reordering or conditionally skipping an earlier snapshot call which shifts the counter; asserting different numbers of snapshots per branch.

Common situations: Incremental test growth after snapshots were committed; renaming steps during a refactor; data-dependent control flow (if/else each with snapshots) executed in a different order than when the file was recorded.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/328f2f149de69f08. Report an issue: GitHub.