Last active
July 23, 2023 16:09
-
-
Save damonbauer/8b69bc92368c680433202f2121f7a3f4 to your computer and use it in GitHub Desktop.
react-native-blob-util mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// __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(), | |
}, | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Derived from https://stackoverflow.com/a/62371311/355512