Konform Matchers
Kotest provides various matchers for use with Konform. They can be used in your tests to assert that a given object is validated or fails validation.
To use these matchers add implementation 'io.kotest:kotest-assertions-konform-jvm:<version>'
or implementation 'io.kotest:kotest-assertions-konform-js:<version>
to your build.
Let's start with a basic data class:
Then given a UserProfile
validator like this:
We can test that instances pass validation like this:
And we can test that instances fail validation with specific error messages like this:
Matcher | Description |
---|---|
validation.shouldBeValid(value) | Asserts that the validation is valid for the given value |
validation.shouldBeInvalid(value) | Asserts that the validation is invalid for the given value |
validation.shouldBeInvalid(value) { block } | Asserts that the validation is invalid for the given value, and then, runs the block with invalid value |