testable-view-swiftui
testable-view-swiftui copied to clipboard
How would you test a .task ?
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 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.
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.