Skip to content

Commit 3628792

Browse files
authored
require non-empty strings for test description (#1981)
1 parent c843a3b commit 3628792

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
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_snapshot()` now errors when called from a `test_that()` that has an empty description (@kevinushey, #1980).
34
* `skip_if_not_installed()` produces a clearer message (@MichaelChirico, #1959).
45
* `with_mock()` and `local_mock()` have been unconditionally deprecated as they will no longer work in future versions of R (#1999).
56
* `expect_condition()` and friends now include the `class` of the expected condition in the failure mesage, if used (#1987).

R/snapshot-reporter.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SnapshotReporter <- R6::R6Class("SnapshotReporter",
4646
tolerance = testthat_tolerance(),
4747
variant = NULL,
4848
trace_env = NULL) {
49+
check_string(self$test, allow_empty = FALSE)
4950
i <- self$new_snaps$append(self$test, variant, save(value))
5051

5152
old_raw <- self$old_snaps$get(self$test, variant, i)

tests/testthat/test-snapshot.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,11 @@ test_that("hint is informative", {
167167
cat(snapshot_accept_hint("foo", "bar.R", reset_output = FALSE))
168168
})
169169
})
170+
171+
test_that("expect_snapshot requires a non-empty test label", {
172+
173+
test_that("", {
174+
expect_error(expect_snapshot(1 + 1))
175+
})
176+
177+
})

0 commit comments

Comments
 (0)