@@ -9,8 +9,12 @@ import 'package:matcher/matcher.dart';
99/// Returns a matcher that matches if the value is structurally equal to
1010/// [expected] .
1111///
12+ /// When [onlyCheckComparable] fields that are not comparable are ignored for
13+ /// the equality check.
14+ ///
1215/// Improves on a simple equality test by offering a detailed mismatch message.
13- Matcher equalsBuilt (Built expected) => _BuiltValueMatcher (expected);
16+ Matcher equalsBuilt (Built expected, {bool onlyCheckComparable = false }) =>
17+ _BuiltValueMatcher (expected, onlyCheckComparable);
1418
1519/// Matcher for [Built] instances.
1620///
@@ -19,8 +23,10 @@ Matcher equalsBuilt(Built expected) => _BuiltValueMatcher(expected);
1923class _BuiltValueMatcher implements Matcher {
2024 final Built _expected;
2125 final Matcher _delegate;
26+ final bool _onlyCheckComparable;
2227
23- _BuiltValueMatcher (this ._expected) : _delegate = equals (_toMap (_expected));
28+ _BuiltValueMatcher (this ._expected, this ._onlyCheckComparable)
29+ : _delegate = equals (_toMap (_expected));
2430
2531 @override
2632 Description describe (Description description) =>
@@ -41,6 +47,8 @@ class _BuiltValueMatcher implements Matcher {
4147 bool matches (dynamic item, Map matchState) {
4248 if (_expected.runtimeType != item.runtimeType) return false ;
4349
50+ if (_onlyCheckComparable && _expected == item) return true ;
51+
4452 return _delegate.matches (_toMap (item), matchState);
4553 }
4654}
0 commit comments