Skip to content

Commit 8c2bd6e

Browse files
authored
Improve failure messages for expect_visible() and expect_invisible() (#2001)
Fixes #1966
1 parent dd39c65 commit 8c2bd6e

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# testthat (development version)
22

3+
* `expect_visible()` and `expect_invisible()` have improved failure messages (#1966).
34
* `expect_snapshot()` now strips line breaks in test descriptions (@LDSamson, #1900).
45
* `expect_snapshot()` now errors when called from a `test_that()` that has an empty description (@kevinushey, #1980).
56
* `skip_if_not_installed()` produces a clearer message (@MichaelChirico, #1959).

R/expect-invisible.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ expect_invisible <- function(call, label = NULL) {
2626

2727
expect(
2828
identical(vis$visible, FALSE),
29-
sprintf("%s does not return invisibly", lab)
29+
sprintf("%s returns visibly, not invisibly.", lab)
3030
)
3131
invisible(vis$value)
3232
}
@@ -39,7 +39,7 @@ expect_visible <- function(call, label = NULL) {
3939

4040
expect(
4141
identical(vis$visible, TRUE),
42-
sprintf("%s does not invisibly", lab)
42+
sprintf("%s returns invisibly, not visibly.", lab)
4343
)
4444
invisible(vis$value)
4545
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# generates useful failure messages
2+
3+
invisible(1) returns invisibly, not visibly.
4+
5+
---
6+
7+
1 returns visibly, not invisibly.
8+

tests/testthat/test-expect-invisible.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ test_that("basic principles of visibility hold", {
66
expect_failure(expect_visible(x <- 1))
77
})
88

9+
test_that("generates useful failure messages", {
10+
11+
expect_snapshot_failure(expect_visible(invisible(1)))
12+
expect_snapshot_failure(expect_invisible(1))
13+
14+
})
15+
916
test_that("invisibly returns evaluated value", {
1017
out <- expect_invisible(expect_invisible(x <- 2 + 2))
1118
expect_equal(out, 4)

0 commit comments

Comments
 (0)