뷰모델 테스트
다음 뷰모델의 load()를 테스트한다면 어떤 케이스를 검증하겠습니까?
@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) }
}
}