-
Notifications
You must be signed in to change notification settings - Fork 341
Description
If you're expecting some condition and test the output using, for instance, testthat::expect_warning(), the output will be the condition message, regardless of whether you are testing against the message or the class:
foo = function(){
rlang::warn("A message", class="warning_A")
}
testthat::expect_warning(foo(), class="warning_A") #OK
testthat::expect_warning(foo(), class="not_warning_A")
#> Error: `foo()` did not throw the expected warning.
#> In addition: Warning message:
#> A message Created on 2021-03-02 by the reprex package (v1.0.0)
It would be a very nice feature to have expect_warning(), expect_error(), etc. outputting the condition class as well (also regardless of what you are testing).
The error message might be different though, and tell specifically if the unexpected value was the message or the class. But this latter part is somewhat sugary.
EDIT: in the case foo() does not throw a warning, it might also be a good idea to state it clearly in the "in addition" info below. For now, the error message can be a bit frustrating as it looks like there is a warning (but not the expected one), but testthat does not want to share it with you.
A waldo-like comparison would be pretty neat: "expected warning message/class" vs "actual warning message/class".