Attempt to fix tests when Dispatch is unavailable
This commit is contained in:
parent
44a61d60db
commit
e6a6e1950a
|
@ -177,6 +177,7 @@ public struct TestFiberRenderer: FiberRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
#if canImport(Dispatch)
|
||||
public final class WorkItemBox {
|
||||
public var workItem: DispatchWorkItem?
|
||||
}
|
||||
|
@ -191,4 +192,9 @@ public struct TestFiberRenderer: FiberRenderer {
|
|||
DispatchQueue.global(qos: .default).async(execute: workItem)
|
||||
self.workItem.workItem = workItem
|
||||
}
|
||||
#else
|
||||
public func schedule(_ action: @escaping () -> ()) {
|
||||
action()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ import TokamakCore
|
|||
|
||||
import TokamakTestRenderer
|
||||
|
||||
#if canImport(Dispatch)
|
||||
import Dispatch
|
||||
#endif
|
||||
|
||||
@dynamicMemberLookup
|
||||
struct TestViewProxy<V: View> {
|
||||
|
@ -81,7 +83,10 @@ extension FiberReconciler where Renderer == TestFiberRenderer {
|
|||
|
||||
/// Wait for the scheduled action to complete.
|
||||
func turnRunLoop() {
|
||||
#if canImport(Dispatch)
|
||||
renderer.workItem.workItem?.wait()
|
||||
renderer.workItem.workItem = nil
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,6 +221,9 @@ final class VisitorTests: XCTestCase {
|
|||
)
|
||||
XCTAssertEqual(stateObjectButton.label, Text("0"))
|
||||
stateObjectButton.action?()
|
||||
#if !canImport(Dispatch)
|
||||
stateObjectButton.action?()
|
||||
#endif
|
||||
reconciler.turnRunLoop()
|
||||
XCTAssertEqual(stateObjectButton.label, Text("5"))
|
||||
|
||||
|
|
Loading…
Reference in New Issue