Skip to content

Commit

Permalink
Fix unintentional dropping of html dependencies (#747)
Browse files Browse the repository at this point in the history
* fix(exercise_result): Fix unintentional dropping of html dependencies

* test(exercise_result): Add test for broken behavior
  • Loading branch information
gadenbuie committed Nov 8, 2022
1 parent 8713e2a commit 7949794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ exercise_result <- function(
feedback$html <- feedback_as_html(feedback)
}

if (is.character(html_output) && any(nzchar(html_output))) {
if (!inherits(html_output, "html") && is.character(html_output) && any(nzchar(html_output))) {
html_output <- htmltools::HTML(html_output)
} else if (length(html_output) == 0) {
html_output <- NULL
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ test_that("exercise_result() turns length-0 html_output into NULL", {
expect_null(exercise_result(html_output = list())$html_output)
})

test_that("exercise_result() doesn't drop html dependencies from `html_output`", {
html_output <- htmltools::attachDependencies(
htmltools::HTML("<p>A basic paragraph.</p>"),
clipboardjs_html_dependency()
)
res <- exercise_result(html_output = html_output)
expect_equal(as.character(res$html_output), as.character(html_output))
expect_equal(htmltools::htmlDependencies(res$html_output), list(clipboardjs_html_dependency()))
})

test_that("exercise_result_as_html() creates html for learnr", {
expect_null(exercise_result_as_html("nope"))
expect_null(exercise_result_as_html(list()))
Expand Down

0 comments on commit 7949794

Please sign in to comment.