tests/testthat/test-promise-map.R

test_that("promise_map handles NULL values", {
  prom2_map <- function(first_res, second_res) {
    f <- function(index) {
      switch(index, first_res, second_res)
    }
    promise_map(1:2, f)
  }

  counter <- 0

  prom2_map("anything", "anything_else") |>
    then(\(x) {
      counter <<- counter + 1
      expect_equal(x, list("anything", "anything_else"))
    }) |>
    wait_for_it()

  prom2_map(NULL, "anything_else") |>
    then(\(x) {
      counter <<- counter + 1
      expect_equal(x, list(NULL, "anything_else"))
    }) |>
    wait_for_it()

  prom2_map("anything", NULL) |>
    then(\(x) {
      counter <<- counter + 1
      expect_equal(x, list("anything", NULL))
    }) |>
    wait_for_it()

  prom2_map(NULL, NULL) |>
    then(\(x) {
      counter <<- counter + 1
      expect_equal(x, list(NULL, NULL))
    }) |>
    wait_for_it()

  expect_equal(counter, 4)
})

Try the promises package in your browser

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

promises documentation built on Nov. 5, 2025, 6:03 p.m.