Skip to content

Instantly share code, notes, and snippets.

@sipamungkas
Created September 8, 2022 07:40
Show Gist options
  • Save sipamungkas/8922cded82ac909cd62369957eb17c81 to your computer and use it in GitHub Desktop.
Save sipamungkas/8922cded82ac909cd62369957eb17c81 to your computer and use it in GitHub Desktop.
MOCK react native blob util package on jestSetup.ts

React native Blob Util Mock for unit test

Package Link: react-native-blob-util

mock code

jest.mock('react-native-blob-util', () => {
  return {
    __esModule: true,
    default: {
      DocumentDir: jest.fn(),
      config: jest.fn(() => ({
        fetch: jest.fn(() => ({
          progress: jest.fn().mockResolvedValue(true),
        })),
      })),
      fs: {
        cp: jest.fn().mockResolvedValue(true),
        dirs: {
          CacheDir: '/mockCacheDir',
        },
        unlink: jest.fn(),
      },
    },
  };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment