Skip to content

Commit 5d4e29b

Browse files
committed
Test task start and cancel callbacks
1 parent d509dd3 commit 5d4e29b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

AndroidSwiftUICore/Tests/AndroidSwiftUICoreTests/EvaluatorTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ struct ModifierTests {
194194
#expect(node.modifiers.contains { $0.kind == "onDisappear" })
195195
}
196196

197+
@Test("task emits start and cancel callback ids that drive the same Task")
198+
func taskStartAndCancel() async {
199+
let host = ViewHost(Text("x").task { try? await Task.sleep(nanoseconds: 10_000_000_000) })
200+
let node = host.evaluate()
201+
let task = node.modifiers.first { $0.kind == "task" }
202+
guard case .int(let start)? = task?.args["start"],
203+
case .int(let cancel)? = task?.args["cancel"] else {
204+
Issue.record("missing start/cancel ids"); return
205+
}
206+
#expect(start != cancel)
207+
host.callbacks.invokeVoid(Int64(start)) // launches the Task
208+
#expect(!_TaskRegistry.running.isEmpty)
209+
host.callbacks.invokeVoid(Int64(cancel)) // cancels and clears it
210+
#expect(_TaskRegistry.running.isEmpty)
211+
}
212+
197213
@Test("onChange emits a token describing the observed value")
198214
func onChange() {
199215
let node = ViewHost(Text("x").onChange(of: 42) {}).evaluate()

0 commit comments

Comments
 (0)