0

我正在尝试测试我的“站点”类是否投射“事件”(使用 Stream 类)

到目前为止我所拥有的:

test('position', () {
    Site site = new Site();

    Function func = (bool isNew) {
      expect(isNew, equals(true));
    };

    site.onPositionChange.listen((bool b) {
      func(b); 
    });

    var callback = expectAsync1(func, count: 1);
    new Timer(new Duration(milliseconds: 100), callback);

    site.position = new Position(x: 1.0, y: 2.0);
  });

不幸的是,它失败了“期望:站点:位置。测试失败:捕获类型'(动态)=>动态'不是'回调'类型'()=>无效'的子类型。”

我在这里做错了什么?

4

1 回答 1

1

The callback to a timer doesn't take one argument. I don't know what you want to test, but here is a version where your func function is called with false from the Timer.

var callback = expectAsync0(() => func(false));  // No need for count if it is 1.
new Timer(new Duration(milliseconds: 100), callback);
于 2013-07-26T16:55:17.273 回答