facebookarchive / ios-snapshot-test-case

Snapshot view unit tests for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ViewController snapshot from xib is the wrong size

pnikolaou opened this issue · comments

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)

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)