diff --git a/src/MMKV.ts b/src/MMKV.ts index 973a5e74..e8b81fa2 100644 --- a/src/MMKV.ts +++ b/src/MMKV.ts @@ -1,6 +1,4 @@ import { createMMKV } from './createMMKV'; -import { createMockMMKV } from './createMMKV.mock'; -import { isJest } from './PlatformChecker'; interface Listener { remove: () => void; @@ -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). */ @@ -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 = {}; } diff --git a/src/PlatformChecker.ts b/src/PlatformChecker.ts deleted file mode 100644 index 94d4d686..00000000 --- a/src/PlatformChecker.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function isJest(): boolean { - if (global.process == null) { - // In a WebBrowser/Electron the `process` variable does not exist - return false; - } - return process.env.JEST_WORKER_ID != null; -} diff --git a/src/createMMKV.mock.ts b/src/createMMKV.mock.ts index c81bb571..223598b8 100644 --- a/src/createMMKV.mock.ts +++ b/src/createMMKV.mock.ts @@ -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(); return { diff --git a/test/hooks.test.tsx b/test/hooks.test.tsx index e24abd16..25bb7be5 100644 --- a/test/hooks.test.tsx +++ b/test/hooks.test.tsx @@ -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(() => {