dart-archive / mock

A library for mocking classes - DEPRECATED
https://pub.dartlang.org/packages/mock
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

Errors thrown from a Mock are not caught as expected #5

Open DartBot opened 9 years ago

DartBot commented 9 years ago

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.

DartBot commented 9 years ago

Comment by sethladd


Added Pkg-mock, Area-Pkg, Triaged labels.