测试发出的流的listen()dart代码

我有一个Dart类,它侦听从StreamController发出的流:

_buttonsUnfoldedSubscription = _messagesListBloc.stream.listen((data) {
      if (data.messageId != _message.id) {
        _state = MessageState.QUESTION;
        notifyListeners();
      }
    });

我尝试为侦听器中的代码创建一个单元测试:

test('should set state to ${MessageState.QUESTION}',() {
            bloc.state = MessageState.OPTIONS;
            controller.sink.add(MessageButtonsUnfolded("another_id"));
            expectLater(bloc.state,MessageState.QUESTION);
          });

问题在于sink.add()事件稍后以异步方式到达。

我如何等待流传递消息以执行测试断言?

wxw111 回答:测试发出的流的listen()dart代码

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167584.html

大家都在问