react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

Jest Mocking react-native-mmkv

Open radelcom opened this issue 3 years ago • 3 comments

Hi,

is there a way or provided way to easily mock this great library?

would be great if we can provide mocks directly from the library similar way to how AsyncStorage does

Thanks!

radelcom avatar Mar 31 '22 20:03 radelcom

Hey, this seems to be very weird to let the user set up all of this - I think there's better examples (e.g. Reanimated) that automatically mock everything

mrousavy avatar Apr 04 '22 09:04 mrousavy

@mrousavy, yeah that looks simpler. Anything that will help other people using this package so that we dont need to look else where or make our own mocking.

radelcom avatar Apr 04 '22 16:04 radelcom

Sure, if you shoot me a PR I'll be happy to review, test and merge it :)

mrousavy avatar Apr 05 '22 09:04 mrousavy

Hey! I think mocking should now work! Thanks everyone! :)

mrousavy avatar Jul 17 '23 11:07 mrousavy

Add a wrapper provider to your App/Component

import { Provider } from 'react-redux';
import store from '../stores/store';

export const renderWithProviderTheme = (component: React.ReactElement) => {
  const { debug, ...rest } = render(
      <Provider store={store}>{component}</Provider>,
  );

  return {
    debug,
    ...rest,
  };
};

import { renderWithProviderTheme } from '...';

describe('Render with provider, store(mmk)', () => {
  test('Should render correctly component', () => {
    renderWithProviderTheme(
      <MyComponent/>,
    );
  });

norellanac avatar Nov 28 '23 20:11 norellanac