Spot the bug
This view model can't be tested without the real network. Tap the line to change.
@MainActor @Observablefinal class OrdersViewModel {var orders: [Order] = []func load() async throws {orders = try await APIService.shared.fetchOrders()}}
Hint 1 of 1
Where does the view model get its service from?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 5
orders = try await APIService.shared.fetchOrders()
Line 5 reaches for a hidden singleton. Inject a small OrdersLoading protocol through init and call it, so tests can pass a stub.