Skip to content

Commit ff8e9f9

Browse files
authored
Merge 8cde224 into 04409d7
2 parents 04409d7 + 8cde224 commit ff8e9f9

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

R/TealAppDriver.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
2525
#' @description
2626
#' Initialize a `TealAppDriver` object for testing a `teal` application.
2727
#'
28-
#' @param app (`teal_app`)
28+
#' @param app (`teal_app` or `list`) Accept the object created by the `init()` function or
29+
#' a list of `ui` and `server` elements that contains teal as a shiny module.
2930
#' @param options (`list`) passed to `shinyApp(options)`. See [shiny::shinyApp()].
3031
#' @param timeout (`numeric`) Default number of milliseconds for any timeout or
3132
#' timeout_ parameter in the `TealAppDriver` class.
@@ -47,7 +48,16 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
4748
timeout = rlang::missing_arg(),
4849
load_timeout = rlang::missing_arg(),
4950
...) {
50-
checkmate::assert_class(app, "teal_app")
51+
checkmate::assert_class(app, c("teal_app", "list"))
52+
if (inherits(app, "list")) {
53+
checkmate::assert_names(
54+
names(app),
55+
must.include = c("ui", "server"),
56+
subset.of = c("ui", "server")
57+
)
58+
checkmate::assert_function(app$server, args = c("input", "output", "session"))
59+
checkmate::assert_class(app$ui, "shiny.tag")
60+
}
5161
# Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout
5262
# It must be set as parameter to the AppDriver
5363
suppressWarnings(

man/TealAppDriver.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-shinytest2-reporter.R

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ testthat::test_that("e2e: reporter tab is visible when reporter is specified (de
1616

1717
testthat::test_that("e2e: reporter tab is visible when the teal ui creation is delayed", {
1818
skip_if_too_deep(5)
19-
app <- shinytest2::AppDriver$new(
20-
shiny::shinyApp(
19+
app <- TealAppDriver$new(
20+
list(
2121
ui = bslib::page_fluid(
2222
uiOutput("teal_as_shiny_module")
2323
),
@@ -30,22 +30,10 @@ testthat::test_that("e2e: reporter tab is visible when the teal ui creation is d
3030
})
3131
srv_teal("teal", data = teal_data(iris = iris), modules = mods)
3232
}
33-
),
34-
height = 1000,
35-
width = 1000
36-
)
37-
38-
# Runs the same check as `app$is_visible` to check if the selector is visible
39-
testthat::expect_true(
40-
unlist(
41-
app$get_js(
42-
sprintf(
43-
"Array.from(document.querySelectorAll('%s')).map(el => el.checkVisibility({}))",
44-
"#teal-reporter_menu_container"
45-
)
46-
)
4733
)
4834
)
35+
36+
testthat::expect_true(app$is_visible(selector = "#teal-reporter_menu_container"))
4937
app$stop()
5038
})
5139

0 commit comments

Comments
 (0)