In the example below I have an injected dependency that is used within a Task.detached. Looks like the container resolves the regular production instance instead of the mock registered in the test in this case. If I use Task instead of Task.detached, the mock instance is resolved correctly during tests. Is this the expected behaviour? How is the intended usage of Factory in this case of a detached task? Thanks!
Code:
func foo() {
Task.detached {
let api = Container.shared.api()
let log = ErrorLog(content: "\(error)")
await api.send(log: log)
}
}
Test
@Suite(.container)
final class MyTests {
private let mockAPI = APIMock()
init() {
Container.shared.api.register { self.mockAPI }
}
@Test
func someTest() async throws {
// do something that calls foo() <-- This does not resolve the mock instance if foo is using Task.detached
}
}
In the example below I have an injected dependency that is used within a
Task.detached. Looks like the container resolves the regular production instance instead of the mock registered in the test in this case. If I useTaskinstead ofTask.detached, the mock instance is resolved correctly during tests. Is this the expected behaviour? How is the intended usage of Factory in this case of a detached task? Thanks!Code:
Test