Created
November 26, 2018 21:44
-
-
Save johnhaley81/f1b6875cdb4ba9abb2f11a190dec5356 to your computer and use it in GitHub Desktop.
Possible addition to tests for printing out custom errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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