Is there a matcher that simultaneously asserts the type of an object and casts it? #928
Unanswered
amomchilov
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I think this overload is what you want. expect(try somethingThatThrows()).to(throwError(errorType: MyCustomError.self) { error in
expect(error.cause) == POSIXError(.ENOMEM)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to make an assertion about the type of an error, and of a field on it. This requires me to cast.
This was my work-around:
Notice how I needed to force cast from
Error
toMyCustomError
in order to gain access to thecause
property. This force-cast shouldn't ever fail (because of the typecheck on the previous line), but it's still a little crufty.Is there a build in matcher that can help with this?
Here are some other alternatives I considered:
Environment
List the software versions you're using:
Please also mention which package manager you used and its version. Delete the
other package managers in this list:
Beta Was this translation helpful? Give feedback.
All reactions