Status: New
Owner: ----
Labels: Type-Defect Priority-Unassigned
New issue 19098 by
da...@google.com: Errors thrown from a Mock are not
caught as expected
http://code.google.com/p/dart/issues/detail?id=19098
What steps will reproduce the problem?
mockbug.dart:
import 'dart:async';
import 'package:unittest/unittest.dart';
import 'package:mock/mock.dart';
void main() {
test("Function", () {
Future doStuff() {
return new Future.error(new StateError("AAAAH!"));
}
return new Future(() {
return doStuff().then((_) {
fail("Expected an error!");
}).catchError((e) {
expect(e, isStateError);
});
}).catchError((e) {
print("Outside caught: $e");
});
});
test("Mock", () {
Mock m = new Mock();
m.when(callsTo("doStuff")).thenReturn(
new Future.error(new StateError("AAAAH!")));
return new Future(() {
return m.doStuff().then((_) {
fail("Expected an error!");
}).catchError((e) {
expect(e, isStateError);
});
}).catchError((e) {
print("Outside caught: $e");
});
});
}
Expected output:
PASS: Function
PASS: Mock
Actual output:
PASS: Function
FAIL: Mock
Caught Bad state: AAAAH!
Dart Editor 1.5.0dev_01_02
Dart SDK 1.5.0dev.1.2
This works fine with a simpler code structure (i.e.: without the enclosing
Future, for example). Unfortunately, the actual code that this minimal
example is based on uses this structure.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings