assertFailsWith<T> function

T assertFailsWith<T>(
  1. void block(), {
  2. String? message,
})

Asserts that a block fails with a specific exception of type T being thrown.

If the assertion fails, the specified message is used unless it is null as a prefix for the failure message.

Return an exception of the expected exception type T that successfully caught.

The returned exception can be inspected further, for example by asserting its property values.

Implementation

T assertFailsWith<T>(
  Unit Function() block, {
  String? message,
}) =>
    throw NotImplementedError(message);