How to use case paths with Swift testing? #228
-
Hi all, I've been following the PointFree courses on swift navigation as of late and I want to implement somethings similar in my app @Observable
final class AppModel
{
@CasePathable
enum Destination
{
case mainScreen(viewModel: MainViewModel)
case onboardingScreen(viewModel: OnboardingFeatureViewModel)
}
var destination: Destination
init(destination: Destination)
{
self.destination = destination
}
func login() async throws
{
}
Now depending on whether login can find already saved credentials I would like to change the destination of the AppModel. How can I test this though? I'm using the new swift testing, but cannot find out how to test whether the correct destination has been chosen: @Test
func loginWithNoAccountsInDatabaseSetsDestinationOnboarding() async throws
{
let appModel = withDependencies {
$0.defaultDatabase = try! appDatabase()
$0.socialMediaClient = MockSocialMediaServer()
} operation: {
AppModel(destination: .mainScreen(viewModel: MainViewModel()))
}
#expect(appModel.destination.is(\AppModel.Destination.mainScreen)) // does not work?
try await appModel.login()
#expect(appModel.destination.is(\AppModel.Destination.onboardingScreen)) // does not work?
} any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @thinkpractice, it should be as simple as this: #expect(appModel.destination.is(\.mainScreen)) Does that work? |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw it does! Thanks so much! It's the one thing I didn't try of course ;) |
Beta Was this translation helpful? Give feedback.
Hi @thinkpractice, it should be as simple as this:
Does that work?