Error Cannot read property 'getRandomBase64' of undefined when running test file
gandarain opened this issue · 4 comments
gandarain commented
paulmars commented
i'm getting this too.
aav7fl commented
I was having this problem as well while using jest
to test my Entrypoint
file.
My Entrypoint
had the following for import Expo SDK@39.0.3
to support calling UUID@8.3.1
:
import 'react-native-get-random-values';
Because my Entrypoint
file was trying to import the react-native-get-random-values
for shallow rendering, it was throwing the Cannot read property 'getRandomBase64' of undefined
error when getting tested since it wasn't being set up correctly during the test.
I ended up solving this by mocking out the function call for getRandomBase64
in my Entrypoint
test file like this:
jest.mock('react-native-get-random-values', () => ({
getRandomBase64: jest.fn(),
}));
jpaulomotta commented
I was having the same problem.
Mocked it a bit differently though.
jest.mock('react-native-get-random-values/getRandomBase64', (arr='bla') => (
Buffer.from(arr, 'base64').toString('ascii')
))