Skip to content

Commit 2d82b31

Browse files
committed
add test
1 parent 88cf661 commit 2d82b31

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tests/testthat/_snaps/theme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@
4040

4141
The `blablabla` theme element must be a <element_text> object.
4242

43+
---
44+
45+
`element_tree` must have names.
46+
47+
---
48+
49+
`element_tree` must have elements constructed with `el_def()`.
50+
i Invalid structure: "foo"
51+
52+
---
53+
54+
Invalid parent in `element_tree`: "foo".
55+
4356
# Theme elements are checked during build
4457

4558
`plot.title.position` must be one of "panel" or "plot", not "test".

tests/testthat/test-theme.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,17 @@ test_that("element tree can be modified", {
312312
p1 <- ggplot() + theme(blablabla = element_line())
313313
expect_snapshot_error(ggplotGrob(p1))
314314

315+
# Expect errors for invalid element trees
316+
expect_snapshot_error(
317+
register_theme_elements(element_tree = list(el_def("rect"), el_def("line")))
318+
)
319+
expect_snapshot_error(
320+
register_theme_elements(element_tree = list(foo = "bar"))
321+
)
322+
expect_snapshot_error(
323+
register_theme_elements(element_tree = list(foo = el_def(inherit = "foo")))
324+
)
325+
315326
# inheritance and final calculation of novel element works
316327
final_theme <- ggplot2:::plot_theme(p, theme_gray())
317328
e1 <- calc_element("blablabla", final_theme)

0 commit comments

Comments
 (0)