Skip to content

Commit

Permalink
add fallback for null values
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Jan 15, 2024
1 parent 17cfecd commit b6513f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dart/lib/src/hint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ class Hint {
// Key/Value Storage

void addAll(Map<String, dynamic> keysAndValues) {
_internalStorage.addAll(keysAndValues);
final withoutNullValues = keysAndValues.map(
(key, value) => MapEntry(key, value ?? "null")
);
_internalStorage.addAll(withoutNullValues);
}

void set(String key, dynamic value) {
_internalStorage[key] = value;
_internalStorage[key] = value ?? "null";
}

dynamic get(String key) {
Expand Down
17 changes: 17 additions & 0 deletions dart/test/hint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ void main() {
expect(sut.screenshot, attachment);
expect(sut.viewHierarchy, attachment);
});

test('Hint init with map null fallback', () {
final hint = Hint.withMap({'fixture-key': null});
expect("null", hint.get("fixture-key"));
});

test('Hint addAll with map null fallback', () {
final hint = Hint();
hint.addAll({'fixture-key': null});
expect("null", hint.get("fixture-key"));
});

test('Hint set with null value fallback', () {
final hint = Hint();
hint.set("fixture-key", null);
expect("null", hint.get("fixture-key"));
});
}

class Fixture {
Expand Down

0 comments on commit b6513f0

Please sign in to comment.