Skip to content

Commit d2fea93

Browse files
Merge branch 'master' into rtl_support_with_test_plans
2 parents e6a629f + 69d029c commit d2fea93

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ dependencies: [
145145
]
146146
```
147147

148+
Next, add `SnapshotTesting` as a dependency of your test target:
149+
150+
```swift
151+
targets: [
152+
.target(name: "MyApp", dependencies: [], path: "Sources"),
153+
.testTarget(name: "MyAppTests", dependencies: ["MyApp", "SnapshotTesting"])
154+
]
155+
```
156+
148157
### Carthage
149158

150159
If you use [Carthage](https://github.com/Carthage/Carthage), you can add the following dependency to your `Cartfile`:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Foundation
2+
import XCTest
3+
4+
extension Snapshotting {
5+
/// Transforms an existing snapshot strategy into one that waits for some amount of time before taking the snapshot. This can be useful for waiting for animations to complete or for UIKit events to finish (i.e. waiting for a UINavigationController to push a child onto the stack).
6+
/// - Parameters:
7+
/// - duration: The amount of time to wait before taking the snapshot.
8+
/// - strategy: The snapshot to invoke after the specified amount of time has passed.
9+
public static func wait(
10+
for duration: TimeInterval,
11+
on strategy: Snapshotting
12+
) -> Snapshotting {
13+
return Snapshotting(
14+
pathExtension: strategy.pathExtension,
15+
diffing: strategy.diffing,
16+
asyncSnapshot: { value in
17+
Async { callback in
18+
let expectation = XCTestExpectation(description: "Wait")
19+
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
20+
expectation.fulfill()
21+
}
22+
_ = XCTWaiter.wait(for: [expectation], timeout: duration + 1)
23+
strategy.snapshot(value).run(callback)
24+
}
25+
})
26+
}
27+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import XCTest
2+
@testable import SnapshotTesting
3+
4+
class WaitTests: XCTestCase {
5+
func testWait() {
6+
var value = "Hello"
7+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
8+
value = "Goodbye"
9+
}
10+
11+
let strategy = Snapshotting.lines.pullback { (_: Void) in
12+
value
13+
}
14+
15+
assertSnapshot(matching: (), as: .wait(for: 1.5, on: strategy))
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Goodbye

0 commit comments

Comments
 (0)