Created
October 12, 2022 20:06
-
-
Save LeBaleiro/08c8474ad5168a36cab7dce4e7faeca5 to your computer and use it in GitHub Desktop.
Dart Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_test/flutter_test.dart'; | |
void main() { | |
test('should edit the original map as default', () { | |
final mockMap = {"item1": "value1"}; | |
expect(mockMap, {"item1": "value1"}); | |
removeFirstItemFromOriginalMap(mockMap); | |
expect(mockMap, {}); | |
}); | |
test('should create a new reference and shouldn\'t edit the original map', | |
() { | |
final mockMap = {"item1": "value1"}; | |
expect(mockMap, {"item1": "value1"}); | |
dontRemoveFirstItemFromOriginalList(mockMap); | |
expect(mockMap, {"item1": "value1"}); | |
}); | |
} | |
void removeFirstItemFromOriginalMap(Map<String, String> mapParam) { | |
mapParam.remove("item1"); | |
} | |
void dontRemoveFirstItemFromOriginalList(Map<String, String> mapParam) { | |
final newMapReference = Map.fromEntries(mapParam.entries); | |
newMapReference.remove("item1"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment