Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Cannot read property 'getRandomBase64' of undefined when running test file #22

Open
gandarain opened this issue Oct 2, 2020 · 4 comments

Comments

@gandarain
Copy link

I try use package uuid and react native get random values to create random uuid. Everything is fine and working. But when I try run my test file using jest, and I get an error Cannot read property 'getRandomBase64' of undefined.
How to solve this error?

Thanks.

Screen Shot 2020-10-02 at 10 37 22

@paulmars
Copy link

paulmars commented Oct 5, 2020

i'm getting this too.

@aav7fl
Copy link

aav7fl commented Oct 14, 2020

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(),
}));

@SnaiNeR
Copy link

SnaiNeR commented Oct 22, 2020

@aav7fl thanks, mocking helped

@jpaulomotta
Copy link

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')
))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants