Replies: 1 comment
-
That is the way to do this. If you are using XCTest you can do this for an entire test class using class MyTests: XCTest {
override func invokeTest() {
withDependencies {
$0.locale = Locale(identifier: "en_US")
} operation: {
super.invokeTest()
}
}
// ...
} Or if you are using Swift Testing, you can use the DependenciesTestSupport library that vends a @Suite(.dependency(\.locale, Locale(identifier: "en_US")))
struct MyTests {
// ...
} Or, alternatively, you can define your own dependency for locales that sets the |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
I am using the locale dependency that is provided by the library [@dependency(.locale) var currentLocale]. I would like to find out how to set a default Locale in all of my tests. Currently, I am specifying the locale dependency for each test that needs it as follows:
But, I would prefer to set a TestValue such as (below), like I do for my other dependencies. Since testValue and previewValue are not provided by the library. I am doing it as below:
However, this doesn't work, because I get this error when I run my tests:
Locale.swift:36: failed - @dependency(.locale) has no test implementation, but was accessed from a test context:
It's not clear to me how to set a default testValue instead I have to set a locale value in each of my tests.
Any help/tips would be greatly appreciated. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions