tests/testthat/test-needs_packages.R

test_that("needs_packages works", {
  
  mockery::stub(what = "requireNamespace",
                where = needs_packages,
                how = FALSE)
  
  expect_error(
    needs_packages(c("memoise", "shiny", "shinyjs")),
    "are needed", class = "rlib_error")
  
  mockery::stub(what = "requireNamespace",
                where = needs_packages,
                how = function(x, ...) {
                  if (x == "shiny") FALSE
                  else TRUE
                })
  
  expect_error(
    needs_packages(c("memoise", "shiny", "shinyjs")),
    "is needed", class = "rlib_error")
  
})

Try the pkgsearch package in your browser

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

pkgsearch documentation built on Oct. 26, 2022, 5:10 p.m.