Implement describeMismatch for TypeMatcher. (#146)
This allows testing utilities that operate on matchers to provide
descriptive errors when TypeMatcher does not match.
Fixes #145
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2d42539..977aba8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.12.8
+
+- Add a mismatch description to `TypeMatcher`.
+
## 0.12.7
- Deprecate the `mirror_matchers.dart` library.
diff --git a/lib/src/type_matcher.dart b/lib/src/type_matcher.dart
index b5ea046..1b30518 100644
--- a/lib/src/type_matcher.dart
+++ b/lib/src/type_matcher.dart
@@ -90,6 +90,13 @@
}
@override
+ Description describeMismatch(
+ item, Description mismatchDescription, Map matchState, bool verbose) {
+ var name = _name ?? _stripDynamic(T);
+ return mismatchDescription.add("is not an instance of '$name'");
+ }
+
+ @override
bool matches(Object item, Map matchState) => item is T;
}
diff --git a/pubspec.yaml b/pubspec.yaml
index d472547..38cf289 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: matcher
-version: 0.12.7
+version: 0.12.8
description: >-
Support for specifying test expectations via an extensible Matcher class.
diff --git a/test/type_matcher_test.dart b/test/type_matcher_test.dart
index f71b890..d9d556e 100644
--- a/test/type_matcher_test.dart
+++ b/test/type_matcher_test.dart
@@ -46,7 +46,8 @@
shouldFail(
const _TestType(),
typeMatcher,
- "Expected: <Instance of '$name'> Actual: <Instance of '_TestType'>",
+ "Expected: <Instance of '$name'> Actual: <Instance of '_TestType'>"
+ " Which: is not an instance of '$name'",
);
});
});