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.

react-native-get-random-values is a native module, so you need to mock it when running unit tests.
One way to do it is as follow: Go to your __mocks__ folder (or create it in the root of the project if it's not there) and place a file named react-native-get-random-values.js (the name is important) with the following content:
export default {
getRandomBase64: jest.fn().mockImplementation(() => {
console.log("getRandomBase64 mock called");
return "mockedBase64";
})
};
To learn more about mocking an entire module, read the Jest docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With