expect function

void expect(
  1. dynamic actual,
  2. dynamic matcher, {
  3. String? reason,
  4. Object? skip,
  5. @Deprecated('Will be removed in 0.13.0.') bool verbose = false,
  6. @Deprecated('Will be removed in 0.13.0.') ErrorFormatter? formatter,
})

Assert that actual matches matcher.

This is the main assertion function. reason is optional and is typically not supplied, as a reason is generated from matcher; if reason is included it is appended to the reason generated by the matcher.

matcher can be a value in which case it will be wrapped in an equals matcher.

If the assertion fails a TestFailure is thrown.

If skip is a String or true, the assertion is skipped. The arguments are still evaluated, but actual is not verified to match matcher. If actual is a Future, the test won't complete until the future emits a value.

If skip is a string, it should explain why the assertion is skipped; this reason will be printed when running the test.

Certain matchers, like completion and throwsA, either match or fail asynchronously. When you use expect with these matchers, it ensures that the test doesn't complete until the matcher has either matched or failed. If you want to wait for the matcher to complete before continuing the test, you can call expectLater instead and await the result.

Implementation

void expect(dynamic actual, dynamic matcher,
    {String? reason,
    Object? /* String|bool */ skip,
    @Deprecated('Will be removed in 0.13.0.') bool verbose = false,
    @Deprecated('Will be removed in 0.13.0.') ErrorFormatter? formatter}) {
  _expect(actual, matcher,
      reason: reason, skip: skip, verbose: verbose, formatter: formatter);
}