Skip to content

vdiffr vs testthat::expect_snapshot() for plots Β #1973

@fh-mthomson

Description

@fh-mthomson

Is vdiffr still recommended over testthat::expect_snapshot() for testing plots (e.g., ggplot2 objects)?

I assume yes (per #617 (comment), #1265 (comment)) 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:

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions