Skip to contents

testthat expectation that the value violates the validator, optionally with a message matching a regular expression.

Usage

expect_invalid(validator, value, ..., regexp = NULL)

Arguments

validator

a restriction object created by restrict().

value

the value to validate.

...

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

regexp

optional regular expression the failure messages must match. All messages are joined with newlines before matching.

Value

value, invisibly.

Details

Requires the testthat package, which is checked when the expectation runs. A missing context dependency is a usage error and propagates.

See also

expect_valid()

Other testthat expectations: expect_valid()

Examples

if (requireNamespace("testthat", quietly = TRUE)) {
  v <- restrict("x") |> require_numeric()
  expect_invalid(v, "a", regexp = "must be numeric")
}