Skip to content

Commit 35f02b9

Browse files
committed
better forward compat for svglite
1 parent 3255f65 commit 35f02b9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/testthat/test-ggsave.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ test_that("ggsave uses theme background as image background", {
5454
ggsave(path, p, device = "svg", width = 5, height = 5)
5555
img <- xml2::read_xml(path)
5656
# Find background rect in svg
57-
bg <- as.character(xml2::xml_find_first(img, xpath = "*/d1:rect/@style"))
57+
bg <- as.character(xml2::xml_find_first(img, xpath = "d1:rect/@style"))
58+
if (is.na(bg)) {
59+
bg <- as.character(xml2::xml_find_first(img, xpath = "d1:g/d1:rect/@style"))
60+
}
5861
expect_true(grepl("fill: #00CCCC", bg))
5962
})
6063

@@ -69,7 +72,10 @@ test_that("ggsave can handle blank background", {
6972
theme(plot.background = element_blank())
7073
ggsave(path, p, device = "svg", width = 5, height = 5)
7174
img <- xml2::read_xml(path)
72-
bg <- as.character(xml2::xml_find_first(img, xpath = "*/d1:rect/@style"))
75+
bg <- as.character(xml2::xml_find_first(img, xpath = "d1:rect/@style"))
76+
if (is.na(bg)) {
77+
bg <- as.character(xml2::xml_find_first(img, xpath = "d1:g/d1:rect/@style"))
78+
}
7379
expect_true(grepl("fill: none", bg))
7480
})
7581

0 commit comments

Comments
 (0)