Skip to content

Instantly share code, notes, and snippets.

@johnhaley81
Created November 26, 2018 21:44
Show Gist options
  • Save johnhaley81/f1b6875cdb4ba9abb2f11a190dec5356 to your computer and use it in GitHub Desktop.
Save johnhaley81/f1b6875cdb4ba9abb2f11a190dec5356 to your computer and use it in GitHub Desktop.
Possible addition to tests for printing out custom errors
/* Snip */
test("Enum failure can be mapped to string", () => {
let message =
switch (Color.decode(jsonInvalidStr)) {
| Belt.Result.Ok(result) => result->Belt.Result.Ok
| Belt.Result.Error(parseError) =>
Decode_ParseError.toDebugString(
x =>
switch (x) {
| `InvalidColor => (_json => "Invalid color")
| `InvalidShape => (_json => "Invalid shape")
| #DecodeBase.failure as f => DecodeBase.failureToString(f)
},
parseError,
)
->Belt.Result.Error
};
expect(message) |> toEqual(Error("Invalid color"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment