File tree Expand file tree Collapse file tree
AndroidSwiftUICore/Tests/AndroidSwiftUICoreTests Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( )
You can’t perform that action at this time.
0 commit comments