Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 45861f5

Browse files
committed
Test can detect that SharedPrefernces is mocked.
Checking wheter a integration test using shared_preferences as the storage backend should be able to check that the current instance is mocked. Not checking could result in overriding could override app runtime data or calling [setMockInitialValues] could lead to overriding data from the test. closes #1 fixing formating
1 parent 176cfb8 commit 45861f5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/shared_preferences/shared_preferences/lib/shared_preferences.dart

+11
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,15 @@ class SharedPreferences {
212212
InMemorySharedPreferencesStore.withData(newValues);
213213
_completer = null;
214214
}
215+
216+
/// reports if this instance is mocked
217+
///
218+
/// An instance turns to being mocked after a call to [setMockInitialValues]
219+
///
220+
/// true if changes on the current delegate will not write to the disk
221+
/// false if shared preferences behaves as normal
222+
@visibleForTesting
223+
bool isMocked() {
224+
return _store is InMemorySharedPreferencesStore;
225+
}
215226
}

0 commit comments

Comments
 (0)