Skip to content

Commit

Permalink
Add type check to theme_set() (#5252)
Browse files Browse the repository at this point in the history
* Add type check to `theme_set()`

* Include test snapshot
  • Loading branch information
teunbrand authored Apr 11, 2023
1 parent e0efd7b commit 2e649bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/theme-current.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ theme_get <- function() {
#' @param new new theme (a list of theme elements)
#' @export
theme_set <- function(new) {
check_object(new, is.theme, "a {.cls theme} object")
old <- ggplot_global$theme_current
ggplot_global$theme_current <- new
invisible(old)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/_snaps/theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

Theme element `test` has "NULL" property without default: fill, colour, linewidth, and linetype

---

`new` must be a <theme> object, not the string "foo".

# element tree can be modified

The `blablabla` theme element is not defined in the element hierarchy.
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ test_that("incorrect theme specifications throw meaningful errors", {
expect_snapshot_error(calc_element("line", theme(line = element_rect())))
register_theme_elements(element_tree = list(test = el_def("element_rect")))
expect_snapshot_error(calc_element("test", theme_gray() + theme(test = element_rect())))
expect_snapshot_error(theme_set("foo"))
})

test_that("element tree can be modified", {
Expand Down

0 comments on commit 2e649bb

Please sign in to comment.