Skip to content

Commit cf688a5

Browse files
committed
Fix tests
1 parent 0287675 commit cf688a5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

man/ggplot_build.Rd

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-layer.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,36 @@ test_that("layer_data returns a data.frame", {
226226
expect_snapshot_error(l$layer_data(mtcars))
227227
})
228228

229+
test_that("get_layer_data works with layer names", {
230+
p <- ggplot() + geom_point(name = "foo") + geom_point(name = "bar")
231+
232+
# name has higher precedence than index
233+
expect_identical(
234+
get_layer_data(p, i = 1L, name = "bar"),
235+
get_layer_data(p, i = 2L)
236+
)
237+
238+
# name falls back to index
239+
expect_snapshot_error(
240+
get_layer_data(p, i = 1L, name = "none")
241+
)
242+
})
243+
244+
test_that("get_layer_grob works with layer names", {
245+
p <- ggplot() + geom_point(name = "foo") + geom_point(name = "bar")
246+
247+
# name has higher precedence than index
248+
expect_identical(
249+
get_layer_grob(p, i = 1L, name = "bar"),
250+
get_layer_grob(p, i = 2L)
251+
)
252+
253+
# name falls back to index
254+
expect_snapshot_error(
255+
get_layer_grob(p, i = 1L, name = "none")
256+
)
257+
})
258+
229259
test_that("data.frames and matrix aesthetics survive the build stage", {
230260
df <- data_frame0(
231261
x = 1:2,

0 commit comments

Comments
 (0)