`expect_type(..., "promise")` fails because of evaluating a promise
(I have testthat v3.3.2 installed)
It seems that it's not possible to test for "promise" type of an object using `expect_type()`. I've dug down and the issue lies in `quasi_label()`, then `labelled_value()`, and finally in [this line](https://github.com/r-lib/testthat/blob/4b13712bb08bbcf19e3b5265e95218043c3d528e/R/quasi-label.R#L65) calling `list(val = value, lab = label)`, where `value` is a promise that gets therefore evaluated. I have no idea how to fix it at the moment.
A reprex:
``` r
x <- environment()
delayedAssign("q", {
message("Promise evaluated")
1
}, assign.env = x)
testthat::expect_type(x[["q"]], "promise")
#> Promise evaluated
#> Error:
#> ! Expected `x[["q"]]` to have type "promise".
#> Actual type: "double"
```
<sup>Created on 2026-04-08 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
关闭于 2026-04-17 2 条评论