Skip to content

Match specific errors in action with Result #3040

Answered by stephencelis
ZevEisenberg asked this question in Q&A
Discussion options

You must be logged in to vote

TestStore.receive is unfortunately already very overloaded and we're looking forward to 2.0 when we can delete some of the older versions, so I'd worry about adding another overload here.

My hunch here, though, is that the action containing this enum should massage the failure into an equatable one if it's important for testability:

-case someOperationResult(Result<User, Error>)
+case someOperationResult(Result<User, SomeOperationError>)

…

 return .run { send in
   await send(
     .someOperationResult(
       Result { try await operation() }
+        .mapError { SomeOperationError(error: $0) }
     )
   )
 }

Or it might be appropriate to use the closure-based receive to test things dir…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stephencelis
Comment options

Answer selected by ZevEisenberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants