ViewInspector icon indicating copy to clipboard operation
ViewInspector copied to clipboard

Xcode hangs on same cases.

Open agiokas opened this issue 5 years ago • 2 comments

I am experiencing strange issue.

Xcode hangs after I run the following "Test" Version 12.0.1 (12A7300)


import SwiftUI

struct ContentView: View {
    @StateObject var vm = ContentVM()

    var body: some View {
        VStack {
            ForEach(vm.items, id: \.self) { title in
                Button(title) {
                    vm.showText = title
                }.padding(.vertical, 5)
            }
        }
    }
}

class ContentVM: ObservableObject {
    @Published var showText: String?

    let items = ["A1", "A2", "A3"]
}


import XCTest
import ViewInspector
import SwiftUI
@testable import AnotherCheck

extension ContentView: Inspectable {}

class AnotherCheckTests: XCTestCase {

    func testButton() throws {
        let sut = ContentView()
        let k  = try sut.inspect().vStack()
    }

}

agiokas avatar Oct 12 '20 09:10 agiokas

The issues has something to do with the @StateObject.

agiokas avatar Oct 12 '20 09:10 agiokas

@agiokas have you tried async inspection? I didn't have time yet to add tests and fully explore @StateObject, but from my current understanding it's closer to "@State" than to "@ObservedObject", so I would try the async inspection instead.

nalexn avatar Oct 12 '20 20:10 nalexn

Feel free to reopen the ticket if the suggestion above did not work for you

nalexn avatar Sep 10 '22 22:09 nalexn