Skip to content

feat(expect): implement toMatchSnapshot()#7003

Open
bartlomieju wants to merge 2 commits intomainfrom
feat/expect-to-match-snapshot
Open

feat(expect): implement toMatchSnapshot()#7003
bartlomieju wants to merge 2 commits intomainfrom
feat/expect-to-match-snapshot

Conversation

@bartlomieju
Copy link
Member

Summary

  • Implements expect().toMatchSnapshot() in the @std/expect module, following Bun/Jest snapshot testing semantics
  • Adds expect.setState() / expect.getState() for Jest-compatible test context management
  • Supports basic snapshots, hint parameters, property matchers with asymmetric matchers, and snapshot update mode (-- --update)
  • Snapshot files are stored in __snapshots__/ alongside test files, using the same format as @std/testing/snapshot

Test plan

  • Error cases: missing test name, .not guard, missing snapshot, property matcher on non-object
  • Snapshot matching: exact match, multi-line objects, arrays, multiple snapshots per test, hint-based keys
  • Snapshot mismatch: diff output with update instructions
  • Round-trip: write snapshots via SnapshotContext, read back and assert match (including special characters like backslashes, backticks, dollar signs, newlines)
  • Full existing expect test suite passes (155 tests)
  • Existing @std/testing/snapshot tests unaffected

🤖 Generated with Claude Code

@bartlomieju bartlomieju requested a review from kt3k as a code owner February 13, 2026 15:39
Adds the `toMatchSnapshot()` matcher to the `@std/expect` module,
following the Jest/Bun snapshot testing API semantics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju force-pushed the feat/expect-to-match-snapshot branch from efb0e9a to ec49316 Compare February 13, 2026 15:58
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 55.47945% with 260 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.66%. Comparing base (54c6107) to head (d2ddae3).

Files with missing lines Patch % Lines
expect/_snapshot_state.ts 46.79% 191 Missing ⚠️
expect/_matchers.ts 67.90% 69 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7003      +/-   ##
==========================================
- Coverage   94.22%   93.66%   -0.56%     
==========================================
  Files         617      618       +1     
  Lines       48569    49153     +584     
  Branches     8534     8578      +44     
==========================================
+ Hits        45765    46041     +276     
- Misses       2736     3042     +306     
- Partials       68       70       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add expect().toMatchInlineSnapshot() for inline snapshot testing,
using Deno.lint.runPlugin to update source files in update mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant