diff --git a/lib/Onyx.js b/lib/Onyx.js index 266775443..43427aefa 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -1100,6 +1100,7 @@ function clear(keysToPreserve = []) { const defaultKeyValuePairs = _.pairs(_.omit(defaultKeyStates, keysToPreserve)); // Remove only the items that we want cleared from storage, and reset others to default + _.each(keysToBeClearedFromStorage, key => cache.drop(key)); return Storage.removeItems(keysToBeClearedFromStorage).then(() => Storage.multiSet(defaultKeyValuePairs)); }); } diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index 09d46e52c..cf2694946 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -117,8 +117,12 @@ describe('Onyx', () => { return Onyx.clear().then(waitForPromisesToResolve); }) .then(() => { + // Test key should be cleared expect(testKeyValue).toBeNull(); - expect(otherTestValue).toBe(null); + + // Other test key should be returned to its default state + expect(otherTestValue).toBe(42); + return Onyx.disconnect(otherTestConnectionID); }); }); @@ -596,7 +600,7 @@ describe('Onyx', () => { expect(mockCallback).toHaveBeenCalledTimes(2); // AND the value for the first call should be null since the collection was not initialized at that point - expect(mockCallback).toHaveBeenNthCalledWith(1, null, 'testPolicy_1'); + expect(mockCallback).toHaveBeenNthCalledWith(1, null, undefined); // AND the value for the second call should be collectionUpdate since the collection was updated expect(mockCallback).toHaveBeenNthCalledWith(2, collectionUpdate.testPolicy_1, 'testPolicy_1');