throwsPropError function

Matcher throwsPropError(
  1. String propName,
  2. [String message = '']
)

A matcher to verify that a PropError is thrown with the provided propName and optional message.

This matcher will not work on PropErrors found within UiComponent2.propTypes. When testing prop type validation - use logsPropError.

Note: The message is matched rather than the Error instance due to Dart's wrapping of all throw as a DomException

Implementation

Matcher throwsPropError(String propName, [String message = '']) {
  return throwsA(anyOf(
      hasToStringValue('V8 Exception'), /* workaround for https://github.com/dart-lang/sdk/issues/26093 */
      hasToStringValue(contains('PropError: Prop $propName. $message'.trim()))
  ));
}