Skip to content

Commit b09f0dd

Browse files
committed
test new behavior
1 parent 7319769 commit b09f0dd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/testthat/_snaps/snapshot-file.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
Error in `snapshot_file_equal_()`:
2323
! 'doesnt-exist.txt' not found.
2424

25+
---
26+
27+
Code
28+
out <- snapshot_file_equal_w_muffle(path_muffle)
29+
Condition
30+
Warning:
31+
Adding new file snapshot: 'tests/testthat/_snaps/muffle-test/test.txt'
32+
2533
# generates informative hint
2634

2735
Code

tests/testthat/test-snapshot-file.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ test_that("warns on first creation", {
136136
expect_true(snapshot_file_equal_(path))
137137
expect_true(file.exists(file.path(snap_dir, "my-test/test.txt")))
138138
expect_false(file.exists(file.path(snap_dir, "my-test/test.new.txt")))
139+
140+
# Similar to shinytest2::AppDriver$expect_values() screenshot snapshot behavior
141+
path_muffle <- write_tmp_lines("muffle-a")
142+
snapshot_file_equal_w_muffle <- function(path) {
143+
withCallingHandlers(
144+
{
145+
snapshot_file_equal(
146+
snap_dir = snap_dir,
147+
snap_test = "muffle-test",
148+
snap_name = "test.txt",
149+
snap_variant = NULL,
150+
path = path,
151+
fail_on_new = TRUE
152+
)
153+
},
154+
expectation = function(e) {
155+
invokeRestart("muffle_expectation")
156+
}
157+
)
158+
}
159+
# Warns on first run: Should fail on new, however it is muffled
160+
expect_snapshot(out <- snapshot_file_equal_w_muffle(path_muffle))
161+
expect_true(out)
139162
})
140163

141164
# helpers -----------------------------------------------------------------

0 commit comments

Comments
 (0)