Testing with the PersistentContainer
Dependencies Addition
#49
-
Greetings all 👋 I've run into an issue with an unimplemented dependancy and I am unsure if I'm using it wrong or if something needs to be tweaked with Given this Reducer: struct ItemListFeature: Reducer {
@Dependency(\.persistentContainer)
var persistentContainer
struct State: Equatable {
var items: Item.FetchedResults = .empty
}
enum Action: Equatable { }
func reduce(into state: inout State, action: Action) -> Effect<Action> {
.none
}
} I created the following test: @MainActor
class ItemListFeatureTests: XCTestCase {
func testBasics() async {
let store = TestStore(
initialState: ItemListFeature.State(),
reducer: ItemListFeature())
store.dependencies.persistentContainer = .default(
inMemory: true
)
}
} I get the following error:
I don't expect to have to override |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hey @Nomad00! |
Beta Was this translation helpful? Give feedback.
-
Hey @tgrapperon ! Apologies that I'm only getting to this sporadically, but I started a repo where I'm hoping to use |
Beta Was this translation helpful? Give feedback.
Hey @Nomad00!
I just tried your code in a standalone project, and I'm not able to reproduce the issue.
It is maybe possible that your host application is hitting this dependency while testing. This kind of issue can also happen if you're statically linking
Dependencies
in your test target.Have you checked this section of the documentation?
In any case, you shouldn't have to implement individual endpoints,
.default(inMemory:)
is a fully fledged persistent store.