tests/testthat/test-validate_standard_inputs.R

testthat::test_that("validate_arm throws shiny error if arm_vec is not a factor", {
  testthat::expect_error(
    validate_arm(1:10),
    "Treatment variable is not a factor",
    class = "shiny.silent.error"
  )

  testthat::expect_error(
    validate_arm(c("A", "B", "C")),
    "Treatment variable is not a factor",
    class = "shiny.silent.error"
  )
})

testthat::test_that("validate_arm throws specific shiny error if arm_vec has just whitespace strings", {
  testthat::expect_error(
    validate_arm(as.factor(c("A", "   "))),
    "Treatment values cannot contain empty strings",
    class = "shiny.silent.error"
  )

  testthat::expect_error(
    validate_arm(as.factor(c("A", ""))),
    "Treatment values cannot contain empty strings",
    class = "shiny.silent.error"
  )
})

testthat::test_that("validate_arm throws no error if arm_vec is a factor", {
  testthat::expect_no_error(
    validate_arm(factor(c("A", "B"), levels = c("A", "B")))
  )

  testthat::expect_no_error(
    validate_arm(factor(c("A", "B"), levels = c("A", "B", "C")))
  )
})

Try the teal.modules.clinical package in your browser

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

teal.modules.clinical documentation built on April 4, 2025, 12:35 a.m.