Files
shiny/tests/testthat/test-reactives.R
Joe Cheng 634b1c7c3c Don't kill the session when a debounced/throttled reactive expr errors (#3624)
* Don't kill the session when a debounced/throttled reactive expr errors

Fixes #3581

* Update NEWS with PR number

Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
2022-06-27 10:57:10 -05:00

41 lines
945 B
R

test_that("can access reactive values directly", {
reactiveConsole(TRUE)
on.exit(reactiveConsole(FALSE))
x1 <- reactiveVal(1)
x1(2)
expect_equal(x1(), 2)
x2 <- reactiveValues(a = 1)
x2$a <- 2
expect_equal(x2$a, 2)
y <- reactive(x1() + x2$a)
expect_equal(y(), 4)
})
test_that("errors in throttled/debounced reactives are catchable", {
reactiveConsole(TRUE)
on.exit(reactiveConsole(FALSE))
# In Shiny 1.7 and earlier, if a throttled/debounced reactive threw an error,
# it would cause internal observers used by the implementations of
# debounce/throttle to error, which would kill the session. The correct
# behavior is to only expose the error to consumers of the throttled/debounced
# reactive.
r <- reactive({
stop("boom")
})
rd <- r %>% debounce(1000)
rt <- r %>% throttle(1000)
observe({
try(rd(), silent = TRUE)
try(rt(), silent = TRUE)
})
expect_silent(flushReact())
})