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

fix: Use .mock extension for MMKV mocks #647

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/MMKV.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { createMMKV } from './createMMKV';
import { createMockMMKV } from './createMMKV.mock';
import { isJest } from './PlatformChecker';

interface Listener {
remove: () => void;
Expand Down Expand Up @@ -29,8 +27,8 @@ export interface MMKVConfiguration {
* ```ts
* const temporaryStorage = new MMKV({ path: '/tmp/' })
* ```
*
* _Notice_: On iOS you can set the AppGroup bundle property to share the same storage between your app and its extensions.
*
* _Notice_: On iOS you can set the AppGroup bundle property to share the same storage between your app and its extensions.
* In this case `path` property will be ignored.
* See more on MMKV configuration [here](https://github.com/Tencent/MMKV/wiki/iOS_tutorial#configuration).
*/
Expand Down Expand Up @@ -147,9 +145,7 @@ export class MMKV implements MMKVInterface {
*/
constructor(configuration: MMKVConfiguration = { id: 'mmkv.default' }) {
this.id = configuration.id;
this.nativeInstance = isJest()
? createMockMMKV()
: createMMKV(configuration);
this.nativeInstance = createMMKV(configuration);
this.functionCache = {};
}

Expand Down
7 changes: 0 additions & 7 deletions src/PlatformChecker.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/createMMKV.mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { NativeMMKV } from 'react-native-mmkv';
import { MMKVConfiguration } from 'react-native-mmkv';

/* Mock MMKV instance for use in tests */
export const createMockMMKV = (): NativeMMKV => {
export const createMMKV = (_: MMKVConfiguration): NativeMMKV => {
const storage = new Map<string, string | boolean | number | Uint8Array>();

return {
Expand Down
2 changes: 2 additions & 0 deletions test/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '@testing-library/react-native';
import { MMKV, useMMKVNumber, useMMKVString } from '../src';

jest.mock('../src/createMMKV', () => require('../src/createMMKV.mock.ts'));

const mmkv = new MMKV();

beforeEach(() => {
Expand Down