Skip to content

Instantly share code, notes, and snippets.

@damonbauer
Last active July 23, 2023 16:09
Show Gist options
  • Save damonbauer/8b69bc92368c680433202f2121f7a3f4 to your computer and use it in GitHub Desktop.
Save damonbauer/8b69bc92368c680433202f2121f7a3f4 to your computer and use it in GitHub Desktop.
react-native-blob-util mock
// __mocks__/react-native-blob-util.js
module.exports = {
__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(),
},
},
};
import ReactNativeBlobUtil from 'react-native-blob-util';
describe('SomeTest', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('handles errors', () => {
ReactNativeBlobUtil.config.mockReturnValueOnce({
fetch: jest.fn().mockReturnValue({
progress: jest.fn(() =>
Object.assign(Promise.reject(), { cancel: jest.fn() }),
),
}),
});
// assertions...
});
});
@damonbauer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment