View source: R/expect_snapshot_doc.R
expect_snapshot_html | R Documentation |
This expectation can be used with 'tinytest' and 'testthat'
to check if a current document of type HTML
matches a target document. When the expectation is checked
for the first time, the expectation fails and a target miniature
of the document is saved in a folder named _tinytest_doconv
or
_snaps
.
expect_snapshot_html( name, x, tolerance = 0.001, engine = c("tinytest", "testthat"), ... )
name |
a string to identify the test. Each document in the test suite must have a unique name. |
x |
file path of an HTML document |
tolerance |
the ratio of different pixels that is acceptable before triggering a failure. |
engine |
test package being used in the test suite, one of "tinytest" or "testthat". |
... |
arguments used by |
A tinytest::tinytest()
or a testthat::expect_snapshot_file object.
file <- tempfile(fileext = ".html") html <- paste0("<html><head><title>hello</title></head>", "<body><h1>Hello World</h1></body></html>\n") cat(html, file = file) ## Not run: if (require("tinytest") && require("webshot2")){ # first run add a new snapshot expect_snapshot_html(x = file, name = "html file", engine = "tinytest") # next runs compare with the snapshot expect_snapshot_html(x = file, name = "html file", engine = "tinytest") # cleaning directory unlink("_tinytest_doconv", recursive = TRUE, force = TRUE) } if (require("testthat") && require("webshot2")){ local_edition(3) # first run add a new snapshot expect_snapshot_html(x = file, name = "html file", engine = "testthat") # next runs compare with the snapshot expect_snapshot_html(x = file, name = "html file", engine = "testthat") } ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.