felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Home Page:https://pub.dev/packages/equatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EquatableMixin does not use EquatableConfig.stringify by default

dalewking opened this issue · comments

Describe the bug
When extending Equatable, toString will by default look at EquatableConfig.stringify to determine what to do, but when using EquatableMixin by default toString just prints class name

To Reproduce

Here is a unit test demonstrating the issue:

import 'package:equatable/equatable.dart';
import 'package:flutter_test/flutter_test.dart';

class FooExtends extends Equatable {
  final int i;

  FooExtends(this.i);

  @override
  List<Object> get props => [i];
}

class FooMixin with EquatableMixin {
  final int i;

  FooMixin(this.i);

  @override
  List<Object> get props => [i];
}

void main() {
  group("Equtable toString default behavior", () {
    test("Equatable base class uses EquatableConfig.stringify by default", () {
      EquatableConfig.stringify = true;

      expect(FooExtends(1).toString(), "FooExtends(1)");
    });
    test("Equatable mixin class uses EquatableConfig.stringify by default", () {
      EquatableConfig.stringify = true;

      expect(FooMixin(1).toString(), "FooMixin(1)");
    });
  });
}

Expected behavior
Both unit tests should pass

Actual Behavior
The mixin case fails:

Expected: 'FooMixin(1)'
  Actual: 'FooMixin'
   Which: is different. Both strings start the same, but the actual value is missing the following trailing characters: (1)

Version
Dart SDK version: 2.10.0-4.0.dev.flutter-9d279d41e3 (be) (Mon Aug 10 08:03:29 2020 +0000) on "macos_x64"

Additional context
The issue is that this line should set stringify to null just like the Equatable base class does

Hey @dalewking 👋
Thanks for bringing this up! It should be fixed in v1.2.4 👍