R 测试包含其他模块的发光模块

R 测试包含其他模块的发光模块,r,testing,shiny,R,Testing,Shiny,在一个大型闪亮的应用程序中,我在其他模块中有很多模块。这些嵌套模块有时还具有输入控件,例如textInput()或actionButton,它们也会触发父模块中的某些事件 以下MWE显示了该问题。 模块summaryServer打印值的摘要,但等待由按钮触发的来自rangeServer的响应。我想要一个特定的forsummaryServer函数,该函数具有来自Shining的testServer()功能,但是如何“单击”包含的rangeServer模块中的按钮以继续?这是关于模拟会议的事吗 测试

在一个大型闪亮的应用程序中,我在其他模块中有很多模块。这些嵌套模块有时还具有输入控件,例如
textInput()
actionButton
,它们也会触发父模块中的某些事件

以下MWE显示了该问题。 模块
summaryServer
打印值的摘要,但等待由按钮触发的来自
rangeServer
的响应。我想要一个特定的for
summaryServer
函数,该函数具有来自Shining的
testServer()
功能,但是如何“单击”包含的
rangeServer
模块中的按钮以继续?这是关于模拟会议的事吗

测试###
这是一个棘手的问题。如果您同时将
ignoreInit
ignoreNULL
设置为
FALSE
,则此功能有效,但这只是因为您最初不再依赖于
go
的更改,这是不可取的

我认为在使用
summaryServer
运行
testServer
时,不可能更改
go
内部的
rangeServer
。但是,您可以使用
{shinytest}
来实现这一点。请注意,这里调用并测试整个应用程序。因此,在使用模块时,必须根据元素的完整id(包括名称空间)调用元素

(我将
go
更改为
action按钮
,其他一切保持不变)

rangeUI
rangeUI <- function(id) {
  actionButton(inputId = NS(id, "go"),label = "Go")
}
test_that("output updates when reactive input changes", {

  # invoke app
  app <- shinytest::ShinyDriver$new("app.R")

  # initially, the button has`nt been clicked and the outputs are empty
  testthat::expect_equal(app$getValue("summary-range-go"), 0)
  testthat::expect_equal(app$getValue("summary-min"), "")

  # click the button
  app$click("summary-range-go")
  testthat::expect_equal(app$getValue("summary-range-go"), 1)
  # testthat::expect_equal(app$getValue("summary-min"), "1")

  # for some reason, the button value increased, hence is clicked,
  # but the outputs have not been triggered yet.
  # another click fixes that
  app$click("summary-range-go")
  testthat::expect_equal(app$getValue("summary-min"), "1")

})