@@ -196,6 +196,31 @@ test_that("theme(validate=FALSE) means do not validate_element", {
196
196
expect_equal(red.before $ theme $ animint.width , 500 )
197
197
})
198
198
199
+ test_that(" theme validation happens at build stage" , {
200
+ # adding a non-valid theme element to a theme is no problem
201
+ expect_silent(theme_gray() + theme(text = 0 ))
202
+
203
+ # the error occurs when we try to render the plot
204
+ p <- ggplot() + theme(text = 0 )
205
+ expect_error(print(p ), " must be an `element_text`" )
206
+
207
+ # without validation, the error occurs when the element is accessed
208
+ p <- ggplot() + theme(text = 0 , validate = FALSE )
209
+ expect_error(print(p ), " text should have class element_text" )
210
+ })
211
+
212
+ test_that(" element tree can be modified" , {
213
+ # we cannot add a new theme element without modifying the element tree
214
+ p <- ggplot() + theme(blablabla = element_text())
215
+ expect_error(print(p ), " Theme element `blablabla` is not defined in the element hierarchy" )
216
+
217
+ # things work once we add a new element to the element tree
218
+ q <- p + theme(
219
+ element_tree = list (blablabla = el_def(" element_text" , " text" ))
220
+ )
221
+ expect_silent(print(q ))
222
+ })
223
+
199
224
test_that(" all elements in complete themes have inherit.blank=TRUE" , {
200
225
inherit_blanks <- function (theme ) {
201
226
all(vapply(theme , function (el ) {
0 commit comments