Bloc: Not sure why this test does not pass

Created on 9 Jun 2020  路  6Comments  路  Source: felangel/bloc

I have this test setup and all seemed to be all ok and the test results look good to me but nevertheless the test failes:

 blocTest(
      'Analyze 9141 response',
      build: () async => CommunicationInitBloc()..init(),
      act: (bloc) => bloc.add(
          CommunicationInitEvent.analyzeGeneralTest(response: _firstReponse)),
      expect: [Analyzed(request: Request(commandList: _otherProtocolsRequest))],
    );

the output of the test is this:

Testing started at 14:06 ...
C:\sdks\flutter\bin\flutter.bat --no-color test --machine --plain-name "Analyze 9141 response" test\communication_init_test.dart
package:test_api                             expect
package:bloc_test/src/bloc_test.dart 143:29  blocTest.<fn>.<fn>
===== asynchronous gap ===========================
dart:async                                   _asyncThenWrapperHelper
package:bloc_test/src/bloc_test.dart         blocTest.<fn>.<fn>
dart:async                                   runZoned
package:bloc_test/src/bloc_test.dart 135:11  blocTest.<fn>

Expected: [
            Analyzed<dynamic>:Analyzed(request:Commands: [atkw0, ate0, ath0, atal, ati, ats0, atl0, atsh6C10F1, 0100, 0900, 0902, atdp] continuous: false id: setup, updateRate: 0 })
          ]
  Actual: [
            Analyzed<dynamic>:Analyzed(request:Commands: [atkw0, ate0, ath0, atal, ati, ats0, atl0, atsh6C10F1, 0100, 0900, 0902, atdp] continuous: false id: setup, updateRate: 0 })
          ]
   Which: was Analyzed<dynamic>:<Analyzed(request:Commands: [atkw0, ate0, ath0, atal, ati, ats0, atl0, atsh6C10F1, 0100, 0900, 0902, atdp] continuous: false id: setup, updateRate: 0 })> instead of Analyzed<dynamic>:<Analyzed(request:Commands: [atkw0, ate0, ath0, atal, ati, ats0, atl0, atsh6C10F1, 0100, 0900, 0902, atdp] continuous: false id: setup, updateRate: 0 })> at location [0]

bloc_test question

Most helpful comment

Actually is all my fault:

The Request had no deep compare. I added Equatable from the same-named package. Just for anybody else reading this. The test failed because the results could not be compared besides a reference compare which is not equal because I create two instances of the Request:

//import 'package:logging/logging.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

//final _log = new Logger('btBloc.request.dart');

class Request extends Equatable {
  Request({
    @required this.commandList,
    this.id = 'setup',
    this.continuous = false,
    this.updateInMilliseconds = 0, //as fast as possible
  });

  final String id;
  final List<String> commandList;
  final int updateInMilliseconds;

  ///TODO change to UnmodifiableListView
  final bool continuous;

  @override
  List<Object> get props => [id, commandList, updateInMilliseconds, continuous];

  @override
  String toString() {
    return 'Commands: ${commandList.toString()} continuous: $continuous id: $id, updateRate: $updateInMilliseconds }';
  }
}

All 6 comments

Hi @ride4sun 馃憢
Thanks for opening an issue!

Are you able to share a link to the app so I can debug it locally? Alternatively, it would help if you could share the Analyzed and Request class implementations. Thanks 馃憤

Actually is all my fault:

The Request had no deep compare. I added Equatable from the same-named package. Just for anybody else reading this. The test failed because the results could not be compared besides a reference compare which is not equal because I create two instances of the Request:

//import 'package:logging/logging.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

//final _log = new Logger('btBloc.request.dart');

class Request extends Equatable {
  Request({
    @required this.commandList,
    this.id = 'setup',
    this.continuous = false,
    this.updateInMilliseconds = 0, //as fast as possible
  });

  final String id;
  final List<String> commandList;
  final int updateInMilliseconds;

  ///TODO change to UnmodifiableListView
  final bool continuous;

  @override
  List<Object> get props => [id, commandList, updateInMilliseconds, continuous];

  @override
  String toString() {
    return 'Commands: ${commandList.toString()} continuous: $continuous id: $id, updateRate: $updateInMilliseconds }';
  }
}

Just an idea. I the strings are equal and the test is failing - there could be a warning to make sure equality comparison is implemented. Just a thought to save time. This is probably a common mistake.

Yeah that's definitely an interesting idea, good point 馃憤

Shall I file a feature request?

yes please 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frankrod picture frankrod  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

krusek picture krusek  路  3Comments

nerder picture nerder  路  3Comments

hivesey picture hivesey  路  3Comments