How to test empty logic reducers designed for navigation only (like NavigationSplitView) ? #2964
-
I have the following reducer: Reducer
struct SettingsFeature {
// MARK: - State
@ObservableState
struct State: Equatable {
var hardwareFeature = HardwareFeature.State()
var cloverFeature = CloverFeature.State()
var sidebarDestinationTag: SidebarDestinationTag? = nil
enum SidebarDestinationTag: Int, Equatable, CaseIterable {
case hardwareFeature = 0
case cloverFeature = 1
}
}
// MARK: - Action
enum Action: BindableAction {
case hardwareFeature(HardwareFeature.Action)
case cloverFeature(CloverFeature.Action)
case binding(BindingAction<State>)
}
// MARK: - Reducer
var body: some ReducerOf<Self> {
BindingReducer()
Scope(state: \.hardwareFeature, action: \.hardwareFeature, child: HardwareFeature.init)
Scope(state: \.cloverFeature, action: \.cloverFeature, child: CloverFeature.init)
}
} I was wondering how can I test that implementation. It works perfectly and suits my purposes, but I want to increase code coverage on my project and I dont know how to properly test it. Is this something to test in UI instead of Unit tests? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Alexminator99, you can test this exactly as you test any other kind of feature. You construct a However, I wouldn't say there is all that much to test in this reducer right now. It simply composes two other features together and doesn't layer on any additional logic. So you might want to wait until there is some actual integration logic in |
Beta Was this translation helpful? Give feedback.
Hi @Alexminator99, you can test this exactly as you test any other kind of feature. You construct a
TestStore
focused on theSettingsFeature
domain, send it actions, and assert how state changes.However, I wouldn't say there is all that much to test in this reducer right now. It simply composes two other features together and doesn't layer on any additional logic. So you might want to wait until there is some actual integration logic in
SettingsFeature
that coordinates things between the hardware and clover features.