Debian Codegraph @

tests/testthat/test-hybrid-chain.R

raw
1 test_that("hybrid_chain preserves visibility", {
2 expect_identical(
3 hybrid_chain(1, withVisible),
4 list(value = 1, visible = TRUE)
5 )
6
7 expect_identical(
8 hybrid_chain(invisible(1), withVisible),
9 list(value = 1, visible = FALSE)
10 )
11
12 expect_identical(
13 hybrid_chain(1, identity, withVisible),
14 list(value = 1, visible = TRUE)
15 )
16
17 expect_identical(
18 hybrid_chain(invisible(1), identity, withVisible),
19 list(value = 1, visible = FALSE)
20 )
21
22 expect_identical(
23 hybrid_chain(1, function(x) invisible(x), withVisible),
24 list(value = 1, visible = FALSE)
25 )
26 })
27
28
29 test_that("hybrid_chain preserves visibility - async", {
30 # only test if promises handles visibility
31 skip_if_not_installed("promises", "1.1.1.9001")
32
33 res <- NULL
34 hybrid_chain(
35 promise_resolve(1),
36 function(value) res <<- withVisible(value)
37 )
38 later::run_now()
39 expect_identical(res, list(value = 1, visible = TRUE))
40
41 res <- NULL
42 hybrid_chain(
43 promise_resolve(invisible(1)),
44 function(value) res <<- withVisible(value)
45 )
46 later::run_now()
47 expect_identical(res, list(value = 1, visible = FALSE))
48
49 res <- NULL
50 hybrid_chain(
51 promise_resolve(1),
52 identity,
53 function(value) res <<- withVisible(value)
54 )
55 for (i in 1:2) later::run_now()
56 expect_identical(res, list(value = 1, visible = TRUE))
57
58 res <- NULL
59 hybrid_chain(
60 promise_resolve(invisible(1)),
61 identity,
62 function(value) res <<- withVisible(value)
63 )
64 for (i in 1:2) later::run_now()
65 expect_identical(res, list(value = 1, visible = FALSE))
66
67 res <- NULL
68 hybrid_chain(
69 promise_resolve(1),
70 function(x) invisible(x),
71 function(value) res <<- withVisible(value)
72 )
73 for (i in 1:2) later::run_now()
74 expect_identical(res, list(value = 1, visible = FALSE))
75
76
77 })