Issue 19098 in dart: Errors thrown from a Mock are not caught as expected

66 views
Skip to first unread message

da...@googlecode.com

unread,
May 30, 2014, 12:09:22 AM5/30/14
to bu...@dartlang.org
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

da...@googlecode.com

unread,
Jun 2, 2014, 11:08:02 AM6/2/14
to bu...@dartlang.org
Updates:
Status: Triaged
Labels: Pkg-mock Area-Pkg

Comment #1 on issue 19098 by seth...@google.com: Errors thrown from a Mock
(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages