Skip to content

Commit 843e34d

Browse files
committed
Update advice
1 parent 1a048b4 commit 843e34d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

vignettes/custom-expectation.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,21 @@ expect_length_ <- function(act, n, trace_env = caller_env()) {
288288
} else {
289289
pass()
290290
}
291-
292-
invisible(act$val)
293291
}
294292
295293
expect_length <- function(object, n) {
296294
act <- quasi_label(rlang::enquo(object))
295+
297296
expect_length_(act, n)
297+
invisible(act$val)
298298
}
299299
```
300300

301301
A few recommendations:
302302

303303
* The helper shouldn't be user-facing, so we give it a `_` suffix to make that clear.
304304
* It's typically easiest for a helper to take the labeled value produced by `quasi_label()`.
305-
* Your helper should usually call both `fail()` and `pass()` and be returned from the wrapping expectation.
305+
* Your helper should usually be called for its side effects (i.e. it calls `fail()` and `pass()`).
306+
* You should return `invisible(act$val)` from the parent expecatation as usual.
306307

307308
Again, you're probably not writing so many expectations that it makes sense for you to go to this effort, but it is important for testthat to get it right.

0 commit comments

Comments
 (0)