Closed dreampiggy closed 4 years ago
This introspectAnimatedImage
method is just a helper method using https://github.com/siteline/SwiftUI-Introspect to introspect the native UIView (UIImageView here for that animatedImageView
variable). I want to test the case:
updateUIView
from SwiftUI is called, then UIImageView.stopAnimating()
is called, and then UIImageView.isAnimating
turn to false.The toturial you post here, seems only showing the case:
However, seems my case is:
Hey @dreampiggy ,
Your use case should be possible to test, however, after you change the Binding value outside, you'd need to trigger the asynchronous inspection described in the next section.
You may use inspect
with delay
parameter defaulting to zero.
This issue can be closed.
For UIViewRepresentable
, you have to wrap that into a standalone native SwiftUI view, using a @State
to pass to the actual test view's @Binding
. And it should have a closure that receive Self
and send it outside. Because the structure is copied or you'll lost the @State
status.
@nalexn Maybe this problem is about how SwiftUI handle the @Binding
& @State
? I test that I can not use Binding(wrappedValue:)
from ViewInspector, to mock the same behavior, must use @State
, this is the root case.
Using the new test code solve the problem:
https://gist.github.com/dreampiggy/0b83d31428b3bed0e5be7ffd7ac4aa02
Founded a new issue related to SwiftUI itself ?
Why same code, SwiftUI's NSViewRepresentable call updateNSView
once, but UIViewRepresentable call updateUIView
twice 😅
Not related to ViewInspector, but just a little curious. Which makes it's a pain to write cross-platform code and test code because of those behavior.
Demo
UIViewRepresentable
Code: Just check https://github.com/SDWebImage/SDWebImageSwiftUI/blob/master/SDWebImageSwiftUI/Classes/AnimatedImage.swift :)Demo Unit Test Code: