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