check<T> function

  1. @useResult
Subject<T> check<T>(
  1. T value, {
  2. String? because,
})

Creates a Subject that can be used to validate expectations against value, with an exception upon a failed expectation.

Expectations that are not satisfied throw a TestFailure to interrupt the currently running test and mark it as failed.

If because is passed it will be included as a "Reason:" line in failure messages.

check(actual).equals(expected);

Implementation

@meta.useResult
Subject<T> check<T>(T value, {String? because}) => Subject._(_TestContext._root(
      value: _Present(value),
      // TODO - switch between "a" and "an"
      label: 'a $T',
      fail: (f) {
        final which = f.rejection.which;
        throw TestFailure([
          ...prefixFirst('Expected: ', f.detail.expected),
          ...prefixFirst('Actual: ', f.detail.actual),
          ...indent(
              prefixFirst('Actual: ', f.rejection.actual), f.detail.depth),
          if (which != null && which.isNotEmpty)
            ...indent(prefixFirst('Which: ', which), f.detail.depth),
          if (because != null) 'Reason: $because',
        ].join('\n'));
      },
      allowAsync: true,
      allowUnawaited: true,
    ));