Flutter Stubbing:使用Stub方法的返回值属性

时间:2019-11-28 08:14:32

标签: mockito stubbing flutter-test dart-unittest dart-mock

嗨,这是我想添加的方法:checkLimit方法。

class MyClass {
final ResponseBase isAvailable =
       await sampleRepository.checkLimit(data: _data);
        if (isAvailable.status == ResponseStatus.notOk) {
          yield NotAvailable(
            ErrorType.limit,
            data: _data,
            errorResponse: isAvailable?.responseError,
          );

          return;
        }
} 

这是我的测试

 test('test when event is ScanQRCode checklimit not ok', () {
      final List<ScanState> expectedStates = <CodeScanState>[
        ScanReady(),
        ScanAvailableFetching(),
        ScanNotAvailable(
          ScanErrorType.Limit,
          redeemData: mockRedeemData,
        ),
      ];

      when(mockPromosRepository.checkLimit(
              redeemData: mockRedeemData))
          .thenAnswer(
              (_) => Future<ResponseBase>.value(mockResponseBase.status));

      expectLater(scanBloc.state, emitsInAnyOrder(expectedStates));

      scanBloc.dispatch(ScanQRCode(mockRedeemData));
    });

通过if条件返回的数据应该是什么?谢谢

0 个答案:

没有答案