Replies: 2 comments
-
Hi @abel3cl, this is not considered a bug in the library, though we may be able to provide a better story to this in 2.0 of the library. The problem is that dependencies are only set in the body of the reducer. But you have accessed a dependency outside the reducer: mutating func handleToggleStyle(_ style: Style) {
@Dependency(\.date.now) var now
…
} …which is used in Toggle(
style.description,
isOn: $store.state[style: style]
) So the There are some improvements in this area we will be able to make in the future, but it will be a slight breaking change and so will have to wait for 2.0. But, for the purpose of UI tests there is an easier way. You can use the That should achieve what you want. Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there! |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your quick reply @mbrandonw and for all your efforts with TCA and all other libraries. Amazing! I didn't know about |
Beta Was this translation helpful? Give feedback.
-
Description
First, apologies if this isn't the better place, perhaps this is more related to swift-dependencies, but I have used SyncUps sample code to reproduce it.
I am not sure if this is a Swift bug or a Dependencies bug.
Basically, an expected a date dependency to be overridden in a particular case and it's not.
You can find the sample project code changes here: abel3cl@5771735
I added 2 properties to SyncUpForm.State date and style (some custom enum with 3 cases)
I also added a button and 3 toggles to SyncUpFormView
The first, sends an action whereas the 3 toggles take a Binding derived from some Bindable store to that style. To derived the binding I am using the subscript technique described in the documentation.
Toggling one of the toggles, changes the style and sets a date range. For example all time or last week.
Tapping the button simulates setting the style to .lastWeek. However this is with a "traditional" domain action.
In addition, I added a new line to App.swift when AppFeature is created, in the withDependencies block I am overriding $0.date.now to some canned Date.
Lastly, I added an environment variable to the scheme to get the same behaviour as UI testing.
When I tap the button "Send with action":

Date is overridden correctly to 14/12/2021 9:12AM UK format
When I toggle last week:

Date is the current now, at 11/03/2025 11:03AM UK format
You can also run the UI tests to verify the behaviour
Checklist
main
branch of this package.Expected behavior
Date.now dependency is overridden and it returns "my" expected value
Actual behavior
Date.now dependency is NOT overridden and it returns the default value. In this case, the "real" now, i.e. present time.
Reproducing project
Find the changes in here: abel3cl@5771735
The Composable Architecture version information
main
Destination operating system
iOS 18.1
Xcode version information
Version 16.1 (16B40)
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions