You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the same problem.
But this problem happens only when I run a unit tests.
When I use the parse the same json in my app (Get the same json as dio response) it's ok,
But when I use the same json as mock value for unit tests, it throws an exception since there is object value {}
What is the best way to handle cases of empty objects?
Why does it happen only in the unit tests when I use the json object as mock value.
(When e value is {}, not null)
Location.fromJson(e as Map<String, dynamic>))
It comes from this:
(When json['locations'] value is [{}], not null)
From the generated file.
The problem is with the Location.fromJson
locations: (json['locations'] as List<dynamic>?)
?.map((e) => Location.fromJson(e as Map<String, dynamic>))
.toList(),
The main problem is with e as Map<String, dynamic> that behaves differently.
Unhandled exception:
type '_Map<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
Thank you in advance.
The text was updated successfully, but these errors were encountered:
Following to this issue:
https://stackoverflow.com/questions/75522984/transforming-empty-nested-map-to-object-exception
I have the same problem.
But this problem happens only when I run a unit tests.
When I use the parse the same json in my app (Get the same json as dio response) it's ok,
But when I use the same json as mock value for unit tests, it throws an exception since there is object value {}
What is the best way to handle cases of empty objects?
Why does it happen only in the unit tests when I use the json object as mock value.
(When
e
value is{}
, not null)It comes from this:
(When
json['locations']
value is[{}]
, not null)From the generated file.
The problem is with the Location.fromJson
The main problem is with
e as Map<String, dynamic>
that behaves differently.Thank you in advance.
The text was updated successfully, but these errors were encountered: