Skip to content

Commit 23fa4d6

Browse files
committed
test(nsview): fix failing recursiveDescription test
To get CI test running with `recursiveDescription` the view size must be set explicitly.
1 parent df55d47 commit 23fa4d6

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Sources/SnapshotTesting/Snapshotting/NSView.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ extension Snapshotting where Value == NSView, Format == NSImage {
6161
image.addRepresentation(bitmapRep)
6262
callback(image)
6363
views.forEach { $0.removeFromSuperview() }
64+
view.appearance = initialAppearance
65+
view.frame = initialFrame
66+
6467
if windowForDrawing != nil {
6568
view.removeFromSuperview()
6669
view.layer = nil
@@ -74,10 +77,8 @@ extension Snapshotting where Value == NSView, Format == NSImage {
7477
// `view.needsLayout = false` does not do anything, but this does.
7578
let bitmapRep2 = view.bitmapImageRepForCachingDisplay(in: view.bounds)!
7679
view.cacheDisplay(in: view.bounds, to: bitmapRep2)
77-
7880
}
79-
view.appearance = initialAppearance
80-
view.frame = initialFrame
81+
8182
}
8283
}
8384
}

Tests/SnapshotTestingTests/SnapshotTestingTests.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,10 @@ final class SnapshotTestingTests: XCTestCase {
246246
button.title = "Push Me"
247247
button.sizeToFit()
248248
button.appearance = NSAppearance(named: .aqua)
249+
button.frame.size = .init(width: 84, height: 32)
249250
assertSnapshot(
250251
matching: button,
251-
as: .image(
252-
size: .init(width: 84, height: 32),
253-
windowForDrawing: .init(backingScaleFactor: 1, colorSpace: .genericRGB)
254-
)
252+
as: .image(windowForDrawing: .init(backingScaleFactor: 1, colorSpace: .genericRGB))
255253
)
256254
assertSnapshot(matching: button, as: .recursiveDescription)
257255
#endif
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[ AF ! LU ] h=--- v=--- NSButton "Push Me" f=(0,0,83,32) b=(-)
1+
[ AF ! U ] h=--- v=--- NSButton "Push Me" f=(0,0,84,32) b=(-)
22
[ A ! U ] h=--- v=--- NSButtonBezelView f=(0,0,84,32) b=(-)
33
[ AF ! U ] h=--- v=--- NSButtonTextField "Push Me" f=(11,7,62,15) b=(-)
44
A=autoresizesSubviews, C=canDrawConcurrently, D=needsDisplay, F=flipped, G=gstate, H=hidden (h=by ancestor), L=needsLayout (l=child needsLayout), U=needsUpdateConstraints (u=child needsUpdateConstraints), O=opaque, P=preservesContentDuringLiveResize, S=scaled/rotated, W=wantsLayer (w=ancestor wantsLayer), V=needsVibrancy (v=allowsVibrancy), #=has surface

0 commit comments

Comments
 (0)