Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Unified Diff: pkg/unittest/test/matchers_test.dart

Issue 11821039: More fixes to unittest (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/unittest/lib/src/future_matchers.dart ('k') | pkg/unittest/test/test_utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/test/matchers_test.dart
diff --git a/pkg/unittest/test/matchers_test.dart b/pkg/unittest/test/matchers_test.dart
index d1d998a7f53078bdeb6fd4fe567f5743dc99da40..c95bfa18c163983b819dfc2ecb15ccfa3eec2156 100644
--- a/pkg/unittest/test/matchers_test.dart
+++ b/pkg/unittest/test/matchers_test.dart
@@ -4,6 +4,7 @@
library unittestTests;
import 'package:unittest/unittest.dart';
+import 'dart:async';
part 'test_utils.dart';
doesNotThrow() {}
@@ -514,6 +515,67 @@ void main() {
});
});
+ group('Future Matchers', () {
+
+ test('completes - unexpected error', () {
+ var completer = new Completer();
+ completer.completeError('X');
+ shouldFail(completer.future, completes,
+ contains('Expected future to complete successfully, '
+ 'but it failed with X'),
+ isAsync: true);
+ });
+
+ test('completes - successfully', () {
+ var completer = new Completer();
+ completer.complete('1');
+ shouldPass(completer.future, completes, isAsync: true);
+ });
+
+ test('throws - unexpected to see normal completion', () {
+ var completer = new Completer();
+ completer.complete('1');
+ shouldFail(completer.future, throws,
+ contains("Expected future to fail, but succeeded with '1'"),
+ isAsync: true);
+ });
+
+ test('throws - expected to see exception', () {
+ var completer = new Completer();
+ completer.completeError('X');
+ shouldPass(completer.future, throws, isAsync: true);
+ });
+
+ test('throws - expected to see exception thrown later on', () {
+ var completer = new Completer();
+ var chained = completer.future.then((_) { throw 'X'; });
+ shouldPass(chained, throws, isAsync: true);
+ completer.complete('1');
+ });
+
+ test('throwsA - unexpected normal completion', () {
+ var completer = new Completer();
+ completer.complete('1');
+ shouldFail(completer.future, throwsA(equals('X')),
+ contains("Expected future to fail, but succeeded with '1'"),
+ isAsync: true);
+ });
+
+ test('throwsA - correct error', () {
+ var completer = new Completer();
+ completer.completeError('X');
+ shouldPass(completer.future, throwsA(equals('X')), isAsync: true);
+ });
+
+ test('throwsA - wrong error', () {
+ var completer = new Completer();
+ completer.completeError('X');
+ shouldFail(completer.future, throwsA(equals('Y')),
+ "Expected: 'Y' but: was 'X'.",
+ isAsync: true);
+ });
+ });
+
group('Predicate Matchers', () {
test('isInstanceOf', () {
shouldFail(0, predicate((x) => x is String, "an instance of String"),
« no previous file with comments | « pkg/unittest/lib/src/future_matchers.dart ('k') | pkg/unittest/test/test_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698