testable-view-swiftui icon indicating copy to clipboard operation
testable-view-swiftui copied to clipboard

How would you test a .task ?

Open smiLLe opened this issue 2 years ago • 2 comments

How would I test an async task in a View which just shows some simple data, loaded from an api?

.task {
   let result = await api.loadData()
   self.data = result
}

smiLLe avatar Mar 28 '24 13:03 smiLLe

@smiLLe hey sorry I just saw. I think to prepare my own testing framewrok. The way is to find a task, find the async action and trigger it. Similar for refreshable.

sisoje avatar Aug 12 '24 07:08 sisoje

I prefer action-inspired approach. You wrap your task code in a method like func viewAppeared() async and do the work inside it. Then you just test this method.

pro100filipp avatar Oct 04 '24 09:10 pro100filipp