expect_pkg_error_classes: Test package error classes

View source: R/pkg_abort.R

expect_pkg_error_classesR Documentation

Test package error classes

Description

When you use pkg_abort() to signal errors, you can use this function to test that those errors are generated as expected.

Usage

expect_pkg_error_classes(object, package, ...)

Arguments

object

An expression that is expected to throw an error.

package

⁠(length-1 character)⁠ The name of the package to use in classes.

...

(character) Components of the class name, from least-specific to most.

Value

The classes of the error invisibly on success or the error on failure. Unlike most testthat expectations, this expectation cannot be usefully chained.

Examples


expect_pkg_error_classes(
  pkg_abort("stbl", "This is a test error", "test_subclass"),
  "stbl",
  "test_subclass"
)
try(
  expect_pkg_error_classes(
    pkg_abort("stbl", "This is a test error", "test_subclass"),
    "stbl",
    "different_subclass"
  )
)


stbl documentation built on April 4, 2026, 5:06 p.m.