From 059348ccbf8a43b4ed749657ccad51d0a6450ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla=20Sancho?= Date: Wed, 5 Nov 2025 13:42:23 +0100 Subject: [PATCH] Explore testServer on modules --- tests/testthat/test-tm_g_association.R | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/testthat/test-tm_g_association.R diff --git a/tests/testthat/test-tm_g_association.R b/tests/testthat/test-tm_g_association.R new file mode 100644 index 000000000..82b44d85a --- /dev/null +++ b/tests/testthat/test-tm_g_association.R @@ -0,0 +1,62 @@ +test_that("tm_g_association fails initially", { + + data <- within(teal_data(), { + require(nestcolor) + CO2 <- CO2 + factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) + CO2[factors] <- lapply(CO2[factors], as.character) + }) + + module <- tm_g_association( + ref = data_extract_spec( + dataname = "CO2", + select = select_spec( + label = "Select variable:", + choices = variable_choices("CO2", c("Plant", "Type", "Treatment")), + selected = "Plant", + fixed = FALSE + ) + ), + vars = data_extract_spec( + dataname = "CO2", + select = select_spec( + label = "Select variables:", + choices = variable_choices("CO2", c("Plant", "Type", "Treatment")), + selected = "Treatment", + multiple = TRUE, + fixed = FALSE + ) + ) + ) + + args <- formals(tm_g_association) + + args$ref <- data_extract_spec( + dataname = "CO2", + select = select_spec( + label = "Select variable:", + choices = variable_choices("CO2", c("Plant", "Type", "Treatment")), + selected = "Plant", + fixed = FALSE + ) + ) + args$vars <- data_extract_spec( + dataname = "CO2", + select = select_spec( + label = "Select variables:", + choices = variable_choices("CO2", c("Plant", "Type", "Treatment")), + selected = "Treatment", + multiple = TRUE, + fixed = FALSE + ) + ) + args$id <- "test" + args$data <- reactive(data) + args <- lapply(args, eval) + testServer(module$server, + args = args[names(formals(module$server))], + expr = { + expect_error(output_q()) + } + ) +})