verifyInOrder top-level property

List<VerificationResult> Function<T>(List<T Function()> recordedInvocations) verifyInOrder

Verifies that a list of methods on a mock object have been called with the given arguments. For example:

  () => cat.eatFood("Milk"),
  () => cat.sound(),
  () => cat.eatFood(any),

This verifies that eatFood was called with "Milk", sound was called with no arguments, and eatFood was then called with some argument.

Returns a list of verification results, one for each call which was verified.

For example, if verifyInOrder is given these calls to verify:

final verification = verifyInOrder([
  () => cat.eatFood(captureAny),
  () => cat.chew(),
  () => cat.eatFood(captureAny),

then verification is a list which contains a captured getter which returns three lists:

  1. a list containing the argument passed to eatFood in the first verified eatFood call,
  2. an empty list, as nothing was captured in the verified chew call,
  3. a list containing the argument passed to eatFood in the second verified eatFood call.

Note: verifyInOrder only verifies that each call was made in the order given, but not that those were the only calls. In the example above, if other calls were made to eatFood or sound between the three given calls, or before or after them, the verification will still succeed.


List<VerificationResult> Function<T>(
  List<T Function()> recordedInvocations,
) get verifyInOrder {
  if (_verifyCalls.isNotEmpty) {
    throw StateError(_verifyCalls.join());
  _verificationInProgress = true;
  return <T>(List<T Function()> _) {
    for (final invocation in _) {
      try {
      } catch (_) {
        if (_ is! TypeError) rethrow;

    _verificationInProgress = false;
    final verificationResults = <VerificationResult>[];
    final tmpVerifyCalls = List<_VerifyCall>.from(_verifyCalls);
    var time = DateTime.fromMillisecondsSinceEpoch(0);
    final matchedCalls = <RealCall>[];
    for (final verifyCall in tmpVerifyCalls) {
      try {
        final matched = verifyCall._findAfter(time);
        verificationResults.add(VerificationResult._(1, matched.capturedArgs));
        time = matched.realCall.timeStamp;
        // ignore: avoid_catching_errors
      } on StateError {
        final mocks = => vc.mock).toSet();
        final allInvocations = mocks
            .expand((m) => m._realCalls)
            .toList(growable: false)
          ..sort((inv1, inv2) => inv1.timeStamp.compareTo(inv2.timeStamp));
        var otherCalls = '';
        if (allInvocations.isNotEmpty) {
          otherCalls = " All calls: ${allInvocations.join(", ")}";
          'Matching call #${tmpVerifyCalls.indexOf(verifyCall)} '
          'not found.$otherCalls',
    for (final call in matchedCalls) {
      call.verified = true;
    return verificationResults;