f <- function() stop("My error!")
expect_that(f(), throws_error())
expect_error(f())
expect_that(f(), throws_error("My error!"))
expect_error(f(), "My error!")
# You can use the arguments of grepl to control the matching
expect_error(f(), "my error!", ignore.case = TRUE)
Run the code above in your browser using DataLab