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.
Originally opened as dart-lang/sdk#19098
This issue was originally filed by da...@google.com
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.