Accessing the correct instance in Swift Testing #247
-
I'm facing an issue accessing the instance of my Here’s a simplified version of my code: // ViewModel
@ObservationIgnored
@Injected(\.authService) private var authService
func signIn() async {
// Sign in logic
}
// Test
@Test
func testSignInWhenSignInSucceeds() async {
Container.shared.authService.register { MockAuthService() }
let viewModel = SignInView.ViewModel()
viewModel.email = "email"
viewModel.password = "password"
await viewModel.signIn()
let authService = Container.shared.authService() // This returns a different instance
} |
Beta Was this translation helpful? Give feedback.
Answered by
hmlongco
Nov 3, 2024
Replies: 1 comment 1 reply
-
Yes, it does. Every time a Factory is asked to resolve an instance it returns a new instance. (Unless cached.) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
FabioFiorita
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it does. Every time a Factory is asked to resolve an instance it returns a new instance. (Unless cached.)