Does ViewInspector support async await?
I have some views that use async await internally and for some reason xcode says I have to use await to init them. Probably they became actors once their members became awaitable? So when I try and run ViewHosting.host I get an exception that "Accessing state Object's object without being installed on a view this will create a new instance each time". And then later within ViewHosting.makeWindow, I get an exception that UIWindow must be from main thread only. The view JsConnector and its sub members does work inside my swiftui app but not in the test. I have some other tests that don't await anything and those run without issue.
func test_getProfile_without_avatar() async throws {
@StateObject var env: EnvironmentVM = EnvironmentVM()
let jsConnector = await JsConnector(coordinator: Coordinator(walletStr: walletStr))
ViewHosting.host(view: jsConnector.environmentObject(env)) // seems to fail here
let coordinator = await jsConnector.coordinator
let profileResult = await coordinator.createProfile(profile: ARProfileDto(userName: userName, fullName: fullName, bio: bio, region: region, website: website))
if case .success(let transactionId) = profileResult {
let profileTransResult = await aws.getProfile(userName: userName)
if case .success(let profile) = profileTransResult {
print("transaction id \(transactionId)")
XCTAssertTrue(profile.id == transactionId)
XCTAssertTrue(profile.userName == userName)
XCTAssertTrue(profile.fullName == fullName)
XCTAssertTrue(profile.bio == bio)
XCTAssertTrue(profile.region == region)
XCTAssertTrue(profile.website == website)
return
}
if case .failure(let error) = profileTransResult {
print(error.localizedDescription)
throw error
}
}
if case .failure(let error) = profileResult {
throw error
}
}
@jsoneaday can you try running the test without @StateObject annotation. From my understanding, this is not needed here but can cause all those weird messages.
#291 should likely have resolved many of these issues. Keep an eye out for when that is released.
for some reason xcode says I have to use await to init them
This is the behavior of @preconcurrency which all views have intrinsically. Basically, because your whole test is async it forces you into concurrency adoption. Given that views are main actor isolated you have to create them with the main actor. That's normally assumed, but with an async test must be explicit.