Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate iPhone 15 Snapshots with Xcode 15, as view.swift doesn't contain those dimensions #838

Open
sparks2209 opened this issue Mar 8, 2024 · 3 comments

Comments

@sparks2209
Copy link

SnapshotTesting uses GitHub issues for bugs. For more general discussion and help, please use GitHub Discussions.

@sparks2209 sparks2209 changed the title How to generate iPhone 14 Snapshots with Xcode 15, as view.swift doesn't contain those dimensions How to generate iPhone 15 Snapshots with Xcode 15, as view.swift doesn't contain those dimensions Mar 8, 2024
@mdm84
Copy link

mdm84 commented Mar 14, 2024

Can we create a Pull Request for add it ?

@jbehrens94
Copy link

extension Snapshotting where Value == UIViewController, Format == UIImage has a method:

public static func image(
    on config: ViewImageConfig,
    precision: Float = 1,
    perceptualPrecision: Float = 1,
    size: CGSize? = nil,
    traits: UITraitCollection = .init()
    )
    -> Snapshotting

You can pass a CGSize object to that method with the @1x pixel resolution of an iPhone.

@jbehrens94
Copy link

jbehrens94 commented Sep 5, 2024

And you can call it through

public func assertSnapshot<Value, Format>(
  matching value: @autoclosure () throws -> Value,
  as snapshotting: Snapshotting<Value, Format>,
  named name: String? = nil,
  record recording: Bool = false,
  timeout: TimeInterval = 5,
  file: StaticString = #file,
  testName: String = #function,
  line: UInt = #line
  )

via the as parameter.

Example:

as: .image(
    ...
    size: CGSize(width: ..., height: ...),
    ...
)

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

No branches or pull requests

3 participants