inheritance-expectations {testthat} | R Documentation |
Tests whether or not an object inherits from any of a list of classes, or
is an instance of a base type. expect_null
is a special case designed
for detecting NULL
.
expect_null(object, info = NULL, label = NULL) expect_type(object, type) expect_is(object, class, info = NULL, label = NULL) expect_s3_class(object, class) expect_s4_class(object, class)
object |
object to test |
info |
extra information to be included in the message (useful when writing tests in loops). |
label |
object label. When |
type |
String giving base type (as returned by |
class |
character vector of class names |
expect_is
is an older form. I'd recommend using expect_s3_class
or expect_s4_class
in order to more clearly convery intent.
Other expectations: comparison-expectations
,
equality-expectations
,
expect_equal_to_reference
,
expect_length
, expect_match
,
expect_named
,
logical-expectations
,
output-expectations
expect_is(1, "numeric") a <- matrix(1:10, nrow = 5) expect_is(a, "matrix") expect_is(mtcars, "data.frame") # alternatively for classes that have an is method expect_true(is.data.frame(mtcars)) f <- factor("a") expect_is(f, "factor") expect_s3_class(f, "factor") expect_type(f, "integer") expect_null(NULL)