expect method Null safety

  1. @protected
Future<void> expect(
  1. Object? val,
  2. Object? expected,
  3. {String? reason}
)

Implementation

@protected
Future<void> expect(Object? val, Object? expected, {String? reason}) async {
  if (inCalculator) {
    if (_expectsSeen++ % pauseEvery == 0) {
      DateTime now = DateTime.now();
      Duration sleep =
          (const Duration(milliseconds: 16)) - now.difference(_lastPause);
      _lastPause = now;
      if (sleep < _minSleep) {
        sleep = _minSleep; // Don't monopolize the CPU
      }
      await Future<void>.delayed(sleep);
      // JS resolution is only 4 ms
    }
  }
  if (val != expected) {
    debugPrint('');
    debugPrint('*** Error in self-test:  $val != expected $expected');
    if (reason != null) {
      debugPrint('  $reason');
      debugPrint('');
    }
    throw CalculatorError(9);
  }
}