Skip to content

Fix deprecated verifySnapshot(record:) in generated tests#165

Merged
BarredEwe merged 1 commit into
BarredEwe:mainfrom
AllDmeat:fix/verifysnapshot-deprecated-record
Jul 8, 2026
Merged

Fix deprecated verifySnapshot(record:) in generated tests#165
BarredEwe merged 1 commit into
BarredEwe:mainfrom
AllDmeat:fix/verifysnapshot-deprecated-record

Conversation

@AllDmeat

Copy link
Copy Markdown
Contributor

The generated PreviewTests call verifySnapshot (and assertSnapshot for AccessibilitySnapshot) with the Bool record: overload, which swift-snapshot-testing deprecated in 1.15+ in favor of record: SnapshotTestingConfiguration.Record?.

In projects that build their test target with warnings-as-errors (SWIFT_TREAT_WARNINGS_AS_ERRORS = YES), the generated file fails to compile:

error: 'verifySnapshot(of:as:named:record:snapshotDirectory:timeout:fileID:file:testName:line:column:)' is deprecated: Use overload with 'record: SnapshotTestingConfiguration.Record?'

Since the generated file is regenerated on every build, consumers cannot edit it, so the only way to keep warnings-as-errors is to fix the template.

Change

In PreviewTestsTemplate.swift, map the Bool preference to Record exactly the way swift-snapshot-testing's own compatibility shim does (Deprecations.swift):

self = recording ? .all : .missing

So record: preferences.record becomes record: preferences.record ? .all : .missing in both the verifySnapshot and the assertSnapshot calls. Behavior is preserved.

Notes

  • .all / .missing exist since swift-snapshot-testing 1.15.0, where SnapshotTestingConfiguration.Record was introduced.
  • Verified the generated call type-checks against swift-snapshot-testing 1.19.2 with no deprecation warning.

🤖 Generated with Claude Code

The generated PreviewTests called verifySnapshot/assertSnapshot with the
Bool 'record' overload, deprecated in swift-snapshot-testing 1.15+ in favor
of 'record: SnapshotTestingConfiguration.Record?'. In projects building tests
with warnings-as-errors this fails the build.

Map the Bool to Record the same way swift-snapshot-testing's own compatibility
shim does: true -> .all, false -> .missing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@BarredEwe
BarredEwe merged commit 6308720 into BarredEwe:main Jul 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants