Viktor K.
Viktor K.

Reputation: 393

BehaviorSubject stream unit test, fail actual data

can You please help me to understand how to test the BehaviorSubject with my custom class(TestClass).

the test returns Instance of 'BehaviorSubject<TestClass>' instead of Instance of 'TestClass.

but with primitive types it work fine

Full error:

ERROR: Expected: should emit an event that <Instance of 'TestClass'>
  Actual: <Instance of 'BehaviorSubject<TestClass>'>
   Which: emitted • Instance of 'TestClass'

bloc example:

class TestDataBloc {
  final testSubject = BehaviorSubject<TestClass>();

  Observable<TestClass> get paymentStream => testSubject.stream;

  createOrder() {
    final TestClass _testData = TestClass(
      id: 100,
      data: "xxx",
    );
    testSubject.sink.add(_testData);
  }

  dispose() async {
    await testSubject.drain();
    testSubject.close();
  }
}

test:

    test('_testData', () async {
      TestDataBloc _testDataBloc = TestDataBloc();

      final TestClass _testData = TestClass(
        id: 100,
        data: "xxx",
      );

      expect(
        _testDataBloc.testSubject.stream,
        emitsInOrder(
          <TestClass>[
            _testData,
          ],
        ),
      );

      _testDataBloc.createOrder();
    });

Thanks

Upvotes: 1

Views: 316

Answers (1)

user2703437
user2703437

Reputation: 66

Make sure you have an equality operator defined for TestClass

Upvotes: 2

Related Questions