Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/review-mock-reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@react-native-async-storage/async-storage": patch
---

Clear existing mock stores before resetting the registry and preserve the default legacy instance's registry identity.

9 changes: 7 additions & 2 deletions packages/async-storage/src/jest/AsyncStorageMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AsyncStorageMemoryImpl implements AsyncStorage {
};
}

const inMemoryDbRegistry = new Map<string, AsyncStorageMemoryImpl>();
const inMemoryDbRegistry = new Map<string, AsyncStorage>();

export function createAsyncStorage(databaseName: string): AsyncStorage {
if (!inMemoryDbRegistry.has(databaseName)) {
Expand All @@ -53,7 +53,12 @@ export function createAsyncStorage(databaseName: string): AsyncStorage {
}

export function clearAllMockStorages(): void {
for (const storage of inMemoryDbRegistry.values()) {
void storage.clear();
}
inMemoryDbRegistry.clear();
inMemoryDbRegistry.set("legacy", legacyStorage);
}

export default createAsyncStorage("legacy");
const legacyStorage = createAsyncStorage("legacy");
export default legacyStorage;
Loading