Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Jun 13, 2024
1 parent 9c3b1bc commit 52b8225
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/testthat/test-interrogate_simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -2133,3 +2133,25 @@ test_that("vars(col) and vars('col') both evaluate to tbl column", {
expect_true(test_col_vals_gt(df, x, vars("y")))

})

test_that("class preserved in `value`", {

# A custom class with a `==` method that simply errors
custom_val <- structure(1L, class = "pb-test-custom-class")
registerS3method(
"==", "pb-test-custom-class", function(x, ...) stop("Bad class for `==`")
)

# We expect error (class preserved) vs. TRUE (class stripped)
expect_error(custom_val == 1L)
expect_true(unclass(custom_val) == 1L)

# Error is correctly thrown and safely caught at interrogate
expect_no_error({
agent <- create_agent(data.frame(col = custom_val)) %>%
col_vals_equal(columns = col, value = 1L) %>%
interrogate()
})
expect_true(agent$validation_set$eval_error)

})

0 comments on commit 52b8225

Please sign in to comment.