-
Notifications
You must be signed in to change notification settings - Fork 128
Closed
Description
I'm using Jest as a test framework. My naive attempts at writing tests for functions that return a Result
typically look like:
expect(callSomeFunction("with", "some", "args")).isOk()).toEqual(true);
expect(callSomeFunction("with", "some", "args"))._unsafeUnwrap()).toEqual(someExpectation);
This is a bit clumsy because:
- I need to double all test calls just for the
isOk()
and_unsafeUnwrap()
parts. Especially if thecallSomeFunction("with", "some", "args")
expression is long, this causes quite some overhead. - When the function fails, the runner only outputs that
isOk()
wasn'ttrue
. Any helpful information in the error object remains hidden. I frequently copy paste the expression into a third line for an ad-hocconsole.log
just to get some information, which of course feels wrong ;). - Using
_unsafeUnwrap
and_unsafeUnwrapErr
basically everywhere looks a bit ugly and feels like an anti-pattern.
I'm be no means a Jest expert and still have to check if it offers something that could help here.
I just wanted to bring up the topic, perhaps there are already some better approaches?
Metadata
Metadata
Assignees
Labels
No labels