Skip to contents

testthat expectation that reports the validator's own messages when the value is invalid, so a failing test shows newdata$x2: must be numeric rather than a generic "error thrown".

Usage

expect_valid(validator, value, ...)

Arguments

validator

a restriction object created by restrict().

value

the value to validate.

...

context arguments passed to the validator (e.g. newdata = df).

Value

value, invisibly.

Details

Requires the testthat package, which is checked when the expectation runs. Every violation is reported, as with validation_errors().

See also

expect_invalid()

Other testthat expectations: expect_invalid()

Examples

if (requireNamespace("testthat", quietly = TRUE)) {
  v <- restrict("x") |> require_numeric()
  expect_valid(v, 1:3)
}