Testing
Testing a view model
If you were testing load() on the view model below, which cases would you verify?
@MainActor @Observable
final class FeedViewModel {
enum State { case idle, loading, loaded([Post]), failed(String) }
private(set) var state: State = .idle
private let repo: PostRepository
init(repo: PostRepository) { self.repo = repo }
func load() async {
state = .loading
do { state = .loaded(try await repo.fetch()) }
catch { state = .failed(error.localizedDescription) }
}
}