File: test-reactives.R

package info (click to toggle)
r-cran-shiny 1.10.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,948 kB
  • sloc: javascript: 39,934; sh: 28; makefile: 20
file content (40 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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())
})