Replies: 2 comments
-
@dusiema The library expects that you define test values in your app target or whatever module hosts the login service dependency. Test/mock values are useful outside tests, for example Xcode previews, which are also defined directly in your app target. That said, we do believe the default behavior of If you truly want to isolate the mock value to tests, then it is up to you to do the extra work of overriding the dependency in |
Beta Was this translation helpful? Give feedback.
-
@stephencelis I truly would like to isolate one implementation of the dependencies to be "test-only". And I would be fine with overriding the dependencies in But even if I do it still creates the error message "has no test implementation, but was accessed from a test context". My solution now is to provide a
This satisfies the mechanics that the
I was just hoping I could avoid defining a dummy I guess my project layout of not using hyper-modularised swift modules and not using structs but protocols for dependencies yields to such subtle differences. I otherwise always look at isowords (and the case studies) to see how to use TCA properly. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey,
This might not be 100% TCA related - but...
I introduced swift-dependencies in my TCA project.
Instead of
structs
I am usingprotocol-based dependencies
.I added an
enum
forDependencyKey
and an extension forDependencyValues
like this:Now I also have a
LoginServiceMock
implementation that is only used for testing and has the only "Target Membership" "appTest" but not "app".That is why I can't just add a
static let testValue: any LoginService = LoginServiceMock()
to the
LoginServiceKey
enum as it is not available because of the target membership.Is there a way to keep the mock implementations in target "test" only and still somehow get the swift-dependencies with TCA to use the mock version?
The error I'm getting right now is:
@Dependency(\.loginService) has no test implementation, but was accessed from a test context: ...
when I run my tests.
EDIT:
In my tests I have a
@testable import app
which includes theextension DependencyValues
and then swift-dependencies complains that the context is "test" but there is no value for test implementation.Beta Was this translation helpful? Give feedback.
All reactions