I was trying to test this function
UserApi createUserApi(String url, String username, String password) {
UserApi userApi = new UserApi(base: route(url), serializers: repo);
userApi.base.basicAuth('$username', '$password');
return userApi;
}
basically, the test was to compare the result of this function with a "manually composition" of it, expecting to have the same result. But It doesn't:
String username = "asd";
String password = "asd";
UserApi userApiTest = new UserApi(base: route("asd"), serializers: repo);
userApiTest.base.basicAuth('$username', '$password');
test("UserApi creation", () {
UserApi userApi = _presenter.createUserApi("asd", "asd", "asd");
expect(userApi, userApiTest);
});
The result is always :
Expected: <Instance of 'UserApi'>
Actual: <Instance of 'UserApi'>
Why are they different? In the debug every property is the same.
You have two different instances of UserApi
. Them having the same property values does not make them equal.
You would need to implement hashCode
and operator==
.
By default only comparing the references to the same instance of an object are considered equal (because they are identical)
See also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With