haveFailedWith function

FailureMatcher haveFailedWith(
  1. Object? outcomes
)

Matches a Result that is a Failure with the given outcomes.

Accepts a single String or a List<String>, mirroring the Failure constructor. Chain FailureMatcher.andContext to also assert the context.

andContext accepts a plain value (compared with equals) or any Matcher from package:matcher — allowing type checks, partial structure assertions, and any custom matcher:

expect(signup, haveFailedWith('unauthorized'));
expect(signup, haveFailedWith(['unauthorized', 'forbidden']));

// plain value
expect(signup, haveFailedWith('validationFailed').andContext({'email': ["can't be blank"]}));

// type check
expect(signup, haveFailedWith('validationFailed').andContext(isA<Map<String, dynamic>>()));

// structure assertion
expect(signup, haveFailedWith('validationFailed').andContext(containsPair('email', contains("can't be blank"))));

Implementation

FailureMatcher haveFailedWith(Object? outcomes) => FailureMatcher(_normalizeOutcomes(outcomes));