Skip to content

Commit

Permalink
Test (and fix) theme errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 22, 2024
1 parent 0bce689 commit d5f14e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 1 addition & 4 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ check_theme <- function(theme,
}
config_abort(
error_pkg,
c(
"{.field error_path} uses theme {.val {theme}}",
i = "Valid themes are: {.val highlight_styles()}"
),
"{.field {error_path}} uses theme {.val {theme}}",
call = error_call
)
}
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/_snaps/theme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# validations yaml specification

Code
build_bslib_(template = list(theme = 1, bootstrap = 5))
Condition
Error in `bs_theme_rules()`:
! template.theme must be a string, not the number 1.
i Edit _pkgdown.yml to fix the problem.
Code
build_bslib_(template = list(theme = "fruit", bootstrap = 5))
Condition
Error in `build_bslib_()`:
! template.theme uses theme "fruit"
i Edit _pkgdown.yml to fix the problem.
Code
build_bslib_(template = list(`theme-dark` = "fruit", bootstrap = 5))
Condition
Error in `build_bslib_()`:
! template.theme-dark uses theme "fruit"
i Edit _pkgdown.yml to fix the problem.

12 changes: 12 additions & 0 deletions tests/testthat/test-theme.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("validations yaml specification", {
build_bslib_ <- function(...) {
pkg <- local_pkgdown_site(meta = list(...))
build_bslib(pkg)
}

expect_snapshot(error = TRUE, {
build_bslib_(template = list(theme = 1, bootstrap = 5))
build_bslib_(template = list(theme = "fruit", bootstrap = 5))
build_bslib_(template = list(`theme-dark` = "fruit", bootstrap = 5))
})
})

0 comments on commit d5f14e4

Please sign in to comment.