tests/testthat/helper-requireNamespace-mock.R

# Mocks `requireNamespace` to return `FALSE` for
# provided dependency package "pkg" to test that
# error occurs when it's not installed.
expect_package_error <- function(pkg, code, msg) {
  testthat::with_mocked_bindings({
    testthat::expect_error(code, paste0("`", pkg, "` must be installed"))
  },
  requireNamespace = function(package, ...) package != pkg,
  .package = "base"
  )
}

Try the usmap package in your browser

Any scripts or data that you put into this service are public.

usmap documentation built on May 29, 2024, 10:26 a.m.