Replies: 1 comment 1 reply
-
@jay-linger What you have sketched out should work totally great, and you can provide a mock implementation of In general, though, we feel that protocols are a bit of a heavy option for environment clients since you typically only have 2 conformances (a live conformance and a mockable one). Instead, we like using structs with endpoints, and then you can either return a live instance, or an instance that mocks each endpoint. struct TodoService {
var getTodos: () async throws -> [Todo]
}
extension TodoService {
static let live = Self(
getTodos: {
let (data, _) = try await URLSession.shared
.data(from: URL(string: "https://jsonplaceholder.typicode.com/todos")!)
return try JSONDecoder().decode([Todo].self, from: data)
}
)
} And then in tests you can instantiate a |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, I apologize for not understanding enough.
Looking at the example code, I made this.
In particular, these changes were made to the environment, is this against your design principles?
Actually, I haven't tested for errors.
I wonder if it will work normally.
But the successful scenario works just fine.
But does this code against your design principles?
Thanks in advance for the reply.
Beta Was this translation helpful? Give feedback.
All reactions