I am trying to add a snapshot test for a SwiftUI view that is using Core Data to drive the UI via the @FetchRequest property wrapper. I would like to add a small bit of logic within the UI and would like to have some snapshot tests to cover it.
Below is a snippet example of the SwiftUI view that I am trying to test.
struct TeamView: View {
@Environment(\.managedObjectContext) var viewContext
@FetchRequest(sortDescriptors: [SortDescriptor(\.name)])
private var teams: FetchedResults<Team>
var body: some View {
NavigationView {
List {
ForEach(teams, id: \.id) { team in
Text(team.name)
}
}
.navigationTitle(Text(TabItem.team.title))
}
}
}
Any ideas how I can create Team
Objects that can then be used within TeamView
to enable testing?