skip to Main Content

i have an event bloc
I want to do a test in this event file
but these props are not covered, how do you make them testable?

enter image description here

here is my code :

test('Validate ChangeTabEvent equality', () {
expect(const ChangeTabEvent('category'),
    equals(const ChangeTabEvent('category')));
});

2

Answers


  1. not sure if I understand you correctly. You want to test props? Not needed, this is a object used by Equatable, it only lists all variables included in this class.

    However, if you want to check if all variables are in params included, you can check this according to the following:

    class Person extends Equatable {  // example
      const Person(this.name);
      final String name;
    
    @override
      List<object?>get props => []
    }
    
    ...
    
    final Person bob = Person("Bob");
    
    test('Validate ChangeTabEvent equality', () {
      expect(bob, equals(Person("Bob"));
    });
    

    fails, because you have not name in params

    Login or Signup to reply.
  2. You can add an expect to check the props if the values are as to what value/s you are expecting.

    One solution to cover those lines would be:

    test('Validate ChangeTabEvent equality', () {
    // Add these lines
    const event = ChangeTabEvent('category');
    expect(event.props, ['category']);
    
    
    expect(const ChangeTabEvent('category'),
        equals(const ChangeTabEvent('category')));
    });
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search