avajs/ava · error · AssertionError

No snapshot available — new snapshots are not created in CI

Error message

No snapshot available — new snapshots are not created in CI environments

What it means

AVA throws this AssertionError from t.snapshot() when no snapshot exists for the assertion (result.actual is falsy) and AVA is running in a CI environment, where new snapshots are never written. This is deliberate: in CI AVA must verify against committed snapshots rather than silently creating new ones, so a missing snapshot is a hard failure instead of an auto-update.

Source

Thrown at lib/assert.js:681

				throw fail(new AssertionError(message ?? 'Could not compare snapshot', {
					asssertion: 't.snapshot()',
					improperUsage,
				}));
			}

			if (result.pass) {
				return pass();
			}

			if (result.actual) {
				throw fail(new AssertionError(message ?? 'Did not match snapshot', {
					assertion: 't.snapshot()',
					formattedDetails: [formatDescriptorDiff(result.actual, result.expected, {invert: true})],
				}));
			} else {
				// This can only occur in CI environments.
				throw fail(new AssertionError(message ?? 'No snapshot available — new snapshots are not created in CI environments', {
					assertion: 't.snapshot()',
				}));
			}
		});

		this.truthy = withSkip((actual, message) => {
			assertMessage(message, 't.truthy()');

			if (actual) {
				return pass();
			}

			throw fail(new AssertionError(message, {
				assertion: 't.truthy()',
				formattedDetails: [formatWithLabel('Value is not truthy:', actual)],
			}));
		});

View on GitHub (pinned to bbfd946322)

Solutions

  1. Run npx ava --update-snapshots locally to create the snapshots, then commit the generated .snap files and push again.
  2. Verify .snap files under test/snapshots/ are tracked by git and not matched by .gitignore rules.
  3. If snapshots should not be used in this environment, remove the t.snapshot() call or guard it, since CI will never create new snapshots.
  4. Ensure the CI job runs the same test files/paths as local so snapshot lookups match.

Example fix

// before (CI log)
// AssertionError: No snapshot available — new snapshots are not created in CI environments

// after (local)
npx ava --update-snapshots
git add test/snapshots/*.snap
git commit -m "add snapshots" && git push
Defensive patterns

Strategy: validation

Validate before calling

// Locally, before pushing:
// 1. npx ava --update-snapshots
// 2. verify snapshots are tracked:
//    git ls-files 'test/snapshots/*.snap'
const {execSync} = require('node:child_process');
const tracked = execSync("git ls-files 'test/snapshots/*.snap'").toString().trim();
if (!tracked) throw new Error('No .snap files committed — CI will fail with "No snapshot available"');

Prevention

When it happens

Trigger: Calling t.snapshot(value) in CI for a test/argument combination that has no recorded snapshot — new snapshot assertion added without updating .snap files, new test file, or a .snap file not committed to the repo — while AVA detects CI (CI=true or AVA_CI_MODE).

Common situations: Developer added t.snapshot() locally, ran tests (snapshots generated locally, not committed) and pushed before committing .snap; CI cache/prune rules exclude *.snap files; running the suite in CI before ever running it locally; .snap files gitignored by a broad ignore rule.

Related errors


AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02). Data as JSON: /api/errors/34ba2d7f4b8d09d3. Report an issue: GitHub.