Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2135

Making test assertions on variant types

$
0
0

Does anyone have a preferred way to making assertions on a variant type? For example something like this:

type httpResponse<'a> =
  | Success('a)
  | Conflict(string)
  | NotFound(string)
  | UnAuthorized(string)


let response = await someTestApi()

// expect(response)->toBe(Success(_))
// expect(response)->toBe(NotFound(_))

So far, I’ve been manually pattern matching and throwing errors:

switch response {
| Success(_) => ()
| err => failwith("Expected 'success'")
}

But the output is unfavorable when a test fails and not easy to debug


Viewing all articles
Browse latest Browse all 2135

Trending Articles