test: validate passing incorrect types to type-specific matchers
diff --git a/test/core_matchers_test.dart b/test/core_matchers_test.dart
index 033002f..b5e75b1 100644
--- a/test/core_matchers_test.dart
+++ b/test/core_matchers_test.dart
@@ -32,11 +32,27 @@
test('isNaN', () {
shouldPass(double.nan, isNaN);
shouldFail(3.1, isNaN, "Expected: NaN Actual: <3.1>");
+
+ shouldFail(
+ 'not a num',
+ isNaN,
+ anyOf(
+ contains("type 'String' is not a subtype of type 'num'"),
+ // For dart2js - will be fixed in follow-up
+ contains('TypeError')));
});
test('isNotNaN', () {
shouldPass(3.1, isNotNaN);
shouldFail(double.nan, isNotNaN, "Expected: not NaN Actual: <NaN>");
+
+ shouldFail(
+ 'not a num',
+ isNotNaN,
+ anyOf(
+ contains("type 'String' is not a subtype of type 'num'"),
+ // For dart2js - will be fixed in follow-up
+ contains('TypeError')));
});
test('same', () {
@@ -91,6 +107,9 @@
matches(r"Expected: return normally"
r" Actual: <Closure.*>"
r" Which: threw StateError:<Bad state: X>"));
+
+ shouldFail(
+ 'not a function', returnsNormally, contains('NoSuchMethodError'));
});
test('hasLength', () {
diff --git a/test/iterable_matchers_test.dart b/test/iterable_matchers_test.dart
index dcd4049..6ed51a4 100644
--- a/test/iterable_matchers_test.dart
+++ b/test/iterable_matchers_test.dart
@@ -55,6 +55,7 @@
"Actual: [1, 2] "
"Which: has value <2> which doesn't match <1> at index 1");
shouldPass(e, everyElement(1));
+ shouldFail('not iterable', everyElement(1), contains('not an Iterable'));
});
test('nested everyElement', () {
@@ -109,6 +110,7 @@
shouldPass(d, anyElement(2));
shouldFail(
e, anyElement(2), "Expected: some element <2> Actual: [1, 1, 1]");
+ shouldFail('not an iterable', anyElement(2), contains('not an Iterable'));
});
test('orderedEquals', () {
@@ -121,6 +123,8 @@
"Expected: equals [2, 1] ordered "
"Actual: [1, 2] "
"Which: was <1> instead of <2> at location [0]");
+ shouldFail(
+ 'not an iterable', orderedEquals([1]), contains('not an iterable'));
});
test('unorderedEquals', () {
@@ -151,6 +155,8 @@
"Actual: [1, 2] "
"Which: has no match for <3> at index 0"
" along with 1 other unmatched");
+ shouldFail(
+ 'not an iterable', unorderedEquals([1]), contains('not an iterable'));
});
test('unorderedMatches', () {
@@ -197,6 +203,8 @@
"<0>] unordered "
"Actual: [1, 2] "
"Which: has no match for a value greater than <3> at index 0");
+ shouldFail('not an iterable', unorderedMatches([greaterThan(1)]),
+ contains('not an iterable'));
});
test('containsAll', () {
@@ -224,6 +232,8 @@
"<a value greater than <1>>] "
"Actual: [-1, 2] "
"Which: has no match for a value greater than <1> at index 1");
+ shouldFail(
+ 'not an iterable', containsAll([1, 2, 3]), contains('not an iterable'));
});
test('containsAllInOrder', () {
@@ -291,6 +301,10 @@
"Expected: pairwise double [1, 4, 9] "
"Actual: [1, 2, 3] "
"Which: has <1> which is not double <1> at index 0");
+ shouldFail(
+ 'not an iterable',
+ pairwiseCompare(e, (e, a) => a + a == e, "double"),
+ contains('not an Iterable'));
});
test('isEmpty', () {
diff --git a/test/numeric_matchers_test.dart b/test/numeric_matchers_test.dart
index 9a365d8..0cfd3cd 100644
--- a/test/numeric_matchers_test.dart
+++ b/test/numeric_matchers_test.dart
@@ -24,6 +24,7 @@
"Expected: a numeric value within <1> of <0> "
"Actual: <-1.001> "
"Which: differs by <1.001>");
+ shouldFail('not a num', closeTo(0, 1), contains('not numeric'));
});
test('inInclusiveRange', () {
@@ -40,6 +41,7 @@
inInclusiveRange(0, 2),
"Expected: be in range from 0 (inclusive) to 2 (inclusive) "
"Actual: <3>");
+ shouldFail('not a num', inInclusiveRange(0, 1), contains('not numeric'));
});
test('inExclusiveRange', () {
@@ -54,6 +56,7 @@
inExclusiveRange(0, 2),
"Expected: be in range from 0 (exclusive) to 2 (exclusive) "
"Actual: <2>");
+ shouldFail('not a num', inExclusiveRange(0, 1), contains('not numeric'));
});
test('inOpenClosedRange', () {
@@ -64,6 +67,7 @@
"Actual: <0>");
shouldPass(1, inOpenClosedRange(0, 2));
shouldPass(2, inOpenClosedRange(0, 2));
+ shouldFail('not a num', inOpenClosedRange(0, 1), contains('not numeric'));
});
test('inClosedOpenRange', () {
@@ -74,5 +78,6 @@
inClosedOpenRange(0, 2),
"Expected: be in range from 0 (inclusive) to 2 (exclusive) "
"Actual: <2>");
+ shouldFail('not a num', inClosedOpenRange(0, 1), contains('not numeric'));
});
}
diff --git a/test/string_matchers_test.dart b/test/string_matchers_test.dart
index 28d085c..ad0ef71 100644
--- a/test/string_matchers_test.dart
+++ b/test/string_matchers_test.dart
@@ -55,6 +55,7 @@
shouldPass('hello', equalsIgnoringCase('HELLO'));
shouldFail('hi', equalsIgnoringCase('HELLO'),
"Expected: 'HELLO' ignoring case Actual: 'hi'");
+ shouldFail(42, equalsIgnoringCase('HELLO'), contains('not a string'));
});
test('equalsIgnoringWhitespace', () {
@@ -65,6 +66,7 @@
"Expected: 'hello world' ignoring whitespace "
"Actual: ' helloworld ' "
"Which: is 'helloworld' with whitespace compressed");
+ shouldFail(42, equalsIgnoringWhitespace('HELLO'), contains('not a string'));
});
test('startsWith', () {
@@ -76,6 +78,7 @@
startsWith('hello '),
"Expected: a string starting with 'hello ' "
"Actual: 'hello'");
+ shouldFail(42, startsWith('hello '), contains('not a string'));
});
test('endsWith', () {
@@ -87,6 +90,7 @@
endsWith(' hello'),
"Expected: a string ending with ' hello' "
"Actual: 'hello'");
+ shouldFail(42, startsWith('hello '), contains('not a string'));
});
test('contains', () {
@@ -124,5 +128,6 @@
shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]')));
shouldFail('cOd', matches('[a-z][0-9][a-z]'),
"Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'");
+ shouldFail(42, matches('[a-z][0-9][a-z]'), contains('not a string'));
});
}