Open fh-mthomson opened 1 month ago
Is vdiffr still recommended over testthat::expect_snapshot() for testing plots (e.g., ggplot2 objects)?
vdiffr
testthat::expect_snapshot()
ggplot2
I assume yes (per https://github.com/r-lib/testthat/issues/617#issuecomment-333415894, https://github.com/r-lib/testthat/issues/1265#issuecomment-1721286411) but wanted to confirm, since testthat has seen a lot of great enhancements in the snapshot realm :)
testthat
Motivating example (modified from #1393): I was hoping (perhaps naively) to use:
test_that("ggplot", { library(ggplot2) expect_snapshot(ggplot(data.frame(), aes(1,2)) + geom_point()) })
But, this errors:
── Error ('test-ggplot.R:4:3'): ggplot ───────────────────────────────────────── Error in `UseMethod("snapshot_replay", x)`: no applicable method for 'snapshot_replay' applied to an object of class "recordedplot" Backtrace: ▆ 1. └─testthat::expect_snapshot(ggplot(data.frame(), aes(1, 2)) + geom_point()) at test-ggplot.R:4:3 2. ├─testthat:::with_is_snapshotting(...) 3. └─testthat:::verify_exec(quo_get_expr(x), quo_get_env(x), replay) 4. ├─base::unlist(lapply(results, replay)) 5. └─base::lapply(results, replay) 6. └─testthat (local) FUN(X[[i]], ...) 7. └─testthat:::snapshot_replay(x, state, transform = transform, cnd_class = cnd_class)
Upon further evaluation, vdiffr has a lot of amazing features to enable comparisons across snapshots (side by side, slider, etc), so will use that indefinitely!
Is
vdiffr
still recommended overtestthat::expect_snapshot()
for testing plots (e.g.,ggplot2
objects)?I assume yes (per https://github.com/r-lib/testthat/issues/617#issuecomment-333415894, https://github.com/r-lib/testthat/issues/1265#issuecomment-1721286411) but wanted to confirm, since
testthat
has seen a lot of great enhancements in the snapshot realm :)Motivating example (modified from #1393): I was hoping (perhaps naively) to use:
But, this errors: