| Index: lib/src/throws_matcher.dart
|
| diff --git a/lib/src/throws_matcher.dart b/lib/src/throws_matcher.dart
|
| index 9790d22a0f760371ef0412103d9718a002f7d730..6807e6d248379ded62e7c6cc6fbef9a04db93ad2 100644
|
| --- a/lib/src/throws_matcher.dart
|
| +++ b/lib/src/throws_matcher.dart
|
| @@ -8,7 +8,9 @@ import 'dart:async';
|
|
|
| import 'package:matcher/matcher.dart' hide fail, expect;
|
|
|
| -import '../unittest.dart';
|
| +import 'expect.dart';
|
| +import 'invoker.dart';
|
| +import 'utils.dart';
|
|
|
| /// This can be used to match two kinds of objects:
|
| ///
|
| @@ -48,26 +50,24 @@ class Throws extends Matcher {
|
| bool matches(item, Map matchState) {
|
| if (item is! Function && item is! Future) return false;
|
| if (item is Future) {
|
| - var done = expectAsync((fn) => fn());
|
| -
|
| + Invoker.current.addOutstandingCallback();
|
| // Queue up an asynchronous expectation that validates when the future
|
| // completes.
|
| item.then((value) {
|
| - done(() {
|
| - fail("Expected future to fail, but succeeded with '$value'.");
|
| - });
|
| + fail("Expected future to fail, but succeeded with '$value'.");
|
| }, onError: (error, trace) {
|
| - done(() {
|
| - if (_matcher == null) return;
|
| - var reason;
|
| - if (trace != null) {
|
| - var stackTrace = trace.toString();
|
| - stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}";
|
| - reason = "Actual exception trace:\n$stackTrace";
|
| - }
|
| - expect(error, _matcher, reason: reason);
|
| - });
|
| - });
|
| + if (_matcher == null) return;
|
| +
|
| + var reason;
|
| + if (trace != null) {
|
| + var stackTrace = terseChain(trace).toString();
|
| + stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}";
|
| + reason = "Actual exception trace:\n$stackTrace";
|
| + }
|
| +
|
| + // Re-run [expect] to get the proper formatting.
|
| + expect(() => throw error, this, reason: reason);
|
| + }).then((_) => Invoker.current.removeOutstandingCallback());
|
| // It hasn't failed yet.
|
| return true;
|
| }
|
|
|