Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit a574104

Browse files
committed
feat(tests): Stringify exceptions while testing them
1 parent 7f33f7f commit a574104

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/_specs.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Expect {
6565
toContain(expected) => unit.expect(actual, unit.contains(expected));
6666
toBe(expected) => unit.expect(actual,
6767
unit.predicate((actual) => identical(expected, actual), '$expected'));
68-
toThrow([exception]) => unit.expect(actual, exception == null ? unit.throws : unit.throwsA(unit.contains(exception)));
68+
toThrow([exception]) => unit.expect(actual, exception == null ? unit.throws : unit.throwsA(new ExceptionContains(exception)));
6969
toBeFalsy() => unit.expect(actual, (v) => v == null ? true : v is bool ? v == false : !(v is Object));
7070
toBeTruthy() => unit.expect(actual, (v) => v is bool ? v == true : v is Object);
7171
toBeDefined() => unit.expect(actual, (v) => v is Object);
@@ -91,6 +91,29 @@ class NotExpect {
9191
unit.predicate((actual) => !identical(expected, actual), '$expected'));
9292
}
9393

94+
class ExceptionContains extends unit.BaseMatcher {
95+
96+
final _expected;
97+
98+
const ExceptionContains(this._expected);
99+
100+
bool matches(item, Map matchState) {
101+
if (item is String) {
102+
return item.indexOf(_expected) >= 0;
103+
}
104+
return matches('$item', matchState);
105+
}
106+
107+
unit.Description describe(unit.Description description) =>
108+
description.add('exception contains ').addDescriptionOf(_expected);
109+
110+
unit.Description describeMismatch(item, unit.Description mismatchDescription,
111+
Map matchState, bool verbose) {
112+
return super.describeMismatch('$item', mismatchDescription, matchState,
113+
verbose);
114+
}
115+
}
116+
94117
$(selector) {
95118
return new JQuery(selector);
96119
}

0 commit comments

Comments
 (0)