You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This came up whilst writing tests. I wanted to assert that an Err instance was what I expected, using Vitest's expect/toEqual. That looks like:
expect(error).toEqual(Err(something))
and recursively compares error and Err(something) property by property.
This fails even when error is essentially identical to Err(something), because the _stack property isn't equal (and can't be).
The workaround is easy, just check and unwrap the Err, then compare the inner value, but it's a slight gotcha if you're not expecting it.
I think this and #77 suggest that maybe stacktrace capturing should be optional, though I'm not really sure what an ergonomic API for that would look like.
Thanks for maintaining this, btw. A Rust-like Result for TS is really useful!
The text was updated successfully, but these errors were encountered:
Yeah that's a fair point, maybe a design decision we need to revisit.
We have a simple custom jest matcher that allows for expect(error).toEqualResult(Err(something)) but it's cumbersome (you need to remember to use it and it currently doesn't support all jest magic with something being a special matcher for example).
This came up whilst writing tests. I wanted to assert that an
Err
instance was what I expected, using Vitest's expect/toEqual. That looks like:expect(error).toEqual(Err(something))
and recursively compares
error
andErr(something)
property by property.This fails even when
error
is essentially identical toErr(something)
, because the_stack
property isn't equal (and can't be).The workaround is easy, just check and unwrap the
Err
, then compare the inner value, but it's a slight gotcha if you're not expecting it.I think this and #77 suggest that maybe stacktrace capturing should be optional, though I'm not really sure what an ergonomic API for that would look like.
Thanks for maintaining this, btw. A Rust-like
Result
for TS is really useful!The text was updated successfully, but these errors were encountered: