Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

ViewController snapshot from xib is the wrong size #212

Open
pnikolaou opened this issue Jan 25, 2017 · 1 comment
Open

ViewController snapshot from xib is the wrong size #212

pnikolaou opened this issue Jan 25, 2017 · 1 comment

Comments

@pnikolaou
Copy link

I am trying to run Snapshot tests for VCs of my project. It's quite a big project so I am using xib files instead of storyboards (plus I am part of a dev team). What I don't understand is why snapshot outcome is not resizing to match current simulator's size. Strangely, if I programmatically add it in a UIWindow then it works perfectly fine. Is it a known issue with usesDrawViewHierarchyInRect? Please check sample code below.

override func setUp() {
     super.setUp()
     self.recordMode = true
     self.usesDrawViewHierarchyInRect = true
}
    
func testSizeClassXibViewControllerSnapshot() {
     let vc = SizeClassViewController.init(nibName: "SizeClassViewController", bundle: nil) // this is size class xib
     
     FBSnapshotVerifyView(vc.view)
     FBSnapshotVerifyLayer(vc.view.layer)
}

The above has a PNG outcome of 1200x1200 on iPhone 7 simulator.

override func setUp() {
     super.setUp()
     self.recordMode = true
     self.usesDrawViewHierarchyInRect = true
}
    
func testSizeClassXibViewControllerSnapshot() {
     let vc = SizeClassViewController.init(nibName: "SizeClassViewController", bundle: nil) // this is size class xib
     
     let window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
     window.addSubview(vc.view)
     vc.view.frame = window.bounds

     FBSnapshotVerifyView(vc.view)
     FBSnapshotVerifyLayer(vc.view.layer)
}

However, this one has the correct size, 750 × 1334

Running Xcode Version 8.2.1 (8C1002)

@lucasecf
Copy link

lucasecf commented Dec 20, 2017

Just to mention I have that I have the same problem. I had a controller declared in a storyboard and it's snapshot was sized fine. After I changed the same controller to be in a xib, now it's generated snapshot is 1200 × 1200 (using iPhone 8 simulator - Xcode 9.2)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants