Check that current is an S3 object that inherits from class

expect_s3_class(current, class, ..., info = NA_character_, exact = FALSE)

Arguments

current

[R object or expression] Object or expression to be tested

class

[character] Expected class of current; may optionally pass NA to assert that current is not an object

...

Ignored

info

[character(1L)] Optional user-defined message; must be a single string value

exact

[logical(1L)] If TRUE, check that class(current) is identical to class; otherwise, check that current inherits class

Value

A tinytest object. A tinytest object is a logical with attributes holding information about the test that was run

See also

testthat equivalent: testthat::expect_s3_class()

Other typing expectation predicates: expect_s4_class(), expect_type()

Examples

expect_s3_class(data.frame(), "data.frame") # Pass
#> ----- PASSED      : <-->
#>  call| expect_s3_class(data.frame(), "data.frame") 
expect_s3_class(1L, "integer") # Fail
#> ----- FAILED[attr]: <-->
#>  call| expect_s3_class(1, "integer")
#>  diff| Expected an S3 object, got an object that is not an S3 object 
expect_s3_class(1L, NA) # Pass
#> ----- PASSED      : <-->
#>  call| expect_s3_class(1, NA) 

expect_s3_class(Matrix::Matrix(), "Matrix") # Fail
#> ----- FAILED[attr]: <-->
#>  call| expect_s3_class(Matrix::Matrix(), "Matrix")
#>  diff| Expected an S3 object, got an object that is not an S3 object 
expect_s3_class(Matrix::Matrix(), NA) # Pass
#> ----- PASSED      : <-->
#>  call| expect_s3_class(Matrix::Matrix(), NA)