tests/testthat/test-hybrid-chain.R

test_that("hybrid_chain preserves visibility", {
  expect_identical(
    hybrid_chain(1, withVisible),
    list(value = 1, visible = TRUE)
  )

  expect_identical(
    hybrid_chain(invisible(1), withVisible),
    list(value = 1, visible = FALSE)
  )

  expect_identical(
    hybrid_chain(1, identity, withVisible),
    list(value = 1, visible = TRUE)
  )

  expect_identical(
    hybrid_chain(invisible(1), identity, withVisible),
    list(value = 1, visible = FALSE)
  )

  expect_identical(
    hybrid_chain(1, function(x) invisible(x), withVisible),
    list(value = 1, visible = FALSE)
  )
})


test_that("hybrid_chain preserves visibility - async", {
  # only test if promises handles visibility
  skip_if_not_installed("promises", "1.1.1.9001")

  res <- NULL
  hybrid_chain(
    promise_resolve(1),
    function(value) res <<- withVisible(value)
  )
  later::run_now()
  expect_identical(res, list(value = 1, visible = TRUE))

  res <- NULL
  hybrid_chain(
    promise_resolve(invisible(1)),
    function(value) res <<- withVisible(value)
  )
  later::run_now()
  expect_identical(res, list(value = 1, visible = FALSE))

  res <- NULL
  hybrid_chain(
    promise_resolve(1),
    identity,
    function(value) res <<- withVisible(value)
  )
  for (i in 1:2) later::run_now()
  expect_identical(res, list(value = 1, visible = TRUE))

  res <- NULL
  hybrid_chain(
    promise_resolve(invisible(1)),
    identity,
    function(value) res <<- withVisible(value)
  )
  for (i in 1:2) later::run_now()
  expect_identical(res, list(value = 1, visible = FALSE))

  res <- NULL
  hybrid_chain(
    promise_resolve(1),
    function(x) invisible(x),
    function(value) res <<- withVisible(value)
  )
  for (i in 1:2) later::run_now()
  expect_identical(res, list(value = 1, visible = FALSE))


})

Try the shiny package in your browser

Any scripts or data that you put into this service are public.

shiny documentation built on Nov. 18, 2023, 1:08 a.m.