Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] removeItems function not working #375

Open
armata99 opened this issue Mar 3, 2025 · 0 comments
Open

[Bug] removeItems function not working #375

armata99 opened this issue Mar 3, 2025 · 0 comments

Comments

@armata99
Copy link

armata99 commented Mar 3, 2025

Describe the bug
removeItems function does not remove anything from store and returns undefined instead of boolean.

To Reproduce

  1. create a test file
  2. add below content and run the tests
import {isLoaded} from 'react-native-mmkv-storage';


describe('bug repro test', () => {
  //from docs
  beforeEach(() => {
    // Install the in-memory adapter
    let mmkvMock = require('react-native-mmkv-storage/jest/dist/jest/memoryStore.js');
    mmkvMock.unmock(); // Cleanup if already mocked
    mmkvMock.mock(); // Mock the storage
  });

  //from docs: Use the storage methods as needed. Everything is mocked now
  it('Mock bindings are installed', () => {
    expect(isLoaded()).toBe(true);
  });

  //my own test
  it('testing removeItems function', () => {
    const storage = new MMKVLoader()
      .setProcessingMode(ProcessingModes.SINGLE_PROCESS)
      .withInstanceID('instance')
      .initialize();

    // Store some items
    storage.setString('key1', 'value1');
    storage.setString('key2', 'value2');
    storage.setString('key3', 'value3');

    // Array with multiple keys
    const keysToRemove = ['key1', 'key2'];

    storage.removeItems(keysToRemove); //does not remove the 2 given keys

    const item1 = storage.getString('key1');
    const item2 = storage.getString('key2');
    const item3 = storage.getString('key3');

    expect(item1).toBeNull(); // Should be null but its not
    expect(item2).toBeNull(); // Should be null but its not
    expect(item3).toBe('value3'); // Should still be 'value3'
  });
});

Expected behavior
items with keys key1 and key2 should be removed from store but they don't. In other words, this test should pass.

Screenshots
not necessary

Platform Information:

  • OS: it's happening in testing with jest. I didn't test it at runtime yet.
  • React Native Version: 0.76.7
  • Library Version ^0.11.2

Additional context
I rewrote my actual code to iterate over keys array and remove them one by one for now. It passes the test that way:)
Let me know if there is anything else you need to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant