tests/testthat/test-gadgets.R

context("Shiny gadgets")

test_that("callFromOtherPackage", {
    NOTAFUNCTION <- sum <- function(x) {
        call <- match.call()
        callFromOtherPackage(call, "base")
    }
    expect_equal(sum(1:4), 10)
    expect_error(
        NOTAFUNCTION(1:4),
        "Please install the latest version of base to access NOTAFUNCTION"
    )
})

with_mock(
    `crunch::callFromOtherPackage` = function(call, pkg) {
        call <- capture.output(print(call))
        halt(pkg, "::", call, " called")
    }, {
        test_that("Gadget calling", {
            expect_error(makeArrayGadget(), "crunchy::makeArrayGadget() called", fixed = TRUE)
            expect_error(
                listDatasets(shiny = TRUE),
                "crunchy::listDatasetGadget(kind = kind, refresh = refresh) called",
                fixed = TRUE
            )
        })
    }
)

Try the crunch package in your browser

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

crunch documentation built on Aug. 31, 2023, 1:07 a.m.