Skip to content

Commit 4336985

Browse files
committed
Mock the test case for AnimatedImage binding value update
1 parent 4d35d16 commit 4336985

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Tests/AnimatedImageTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ class AnimatedImageTests: XCTestCase {
9090
func testAnimatedImageBinding() throws {
9191
let expectation = self.expectation(description: "AnimatedImage binding control")
9292
let binding = Binding<Bool>(wrappedValue: true)
93+
var context: AnimatedImage.Context?
9394
let imageView = AnimatedImage(name: "TestLoopCount.gif", bundle: testImageBundle(), isAnimating: binding)
95+
.onViewCreate { _, c in
96+
context = c
97+
}
9498
let introspectView = imageView.introspectAnimatedImage { animatedImageView in
9599
if let animatedImage = animatedImageView.image as? SDAnimatedImage {
96100
XCTAssertEqual(animatedImage.animatedImageLoopCount, 1)
@@ -106,12 +110,8 @@ class AnimatedImageTests: XCTestCase {
106110
binding.wrappedValue = false
107111
XCTAssertFalse(binding.wrappedValue)
108112
XCTAssertFalse(imageView.isAnimating)
109-
// TODO: current the Binding value can not been mocked, hardcode here to call `SDAnimatedImageView.stopAnimating`
110-
#if os(iOS) || os(tvOS)
111-
animatedImageView.stopAnimating()
112-
#else
113-
animatedImageView.animates = false
114-
#endif
113+
// Currently ViewInspector's @Binding value update does not trigger `UIViewRepresentable.updateUIView`, mock here
114+
imageView.updateView(animatedImageView.superview as! AnimatedImageViewWrapper, context: context!)
115115
#if os(iOS) || os(tvOS)
116116
XCTAssertFalse(animatedImageView.isAnimating)
117117
#else

0 commit comments

Comments
 (0)