Open codeofdiego opened 3 years ago
Hi,
Did you find a solution?
@codeofdiego @kkmate - I got around this by doing this in my test file:
import React from 'react';
// other imports...
jest.mock('react-native', () => {
const REACT_NATIVE = jest.requireActual('react-native');
REACT_NATIVE.NativeModules.PdfViewManager = {
supportPDFKit: jest.fn(() => true),
};
REACT_NATIVE.NativeModules.PdfManager = {
loadFile: jest.fn().mockResolvedValue([]),
};
return REACT_NATIVE;
});
describe('Test', () => {
...
});
Still working through some other issues, but it's at least a start...
(this is taken from here: https://github.com/facebook/react-native/issues/28839#issuecomment-625453688)
What
react-native
version are you using? 0.63.3What
react-native-pdf
version are you using? 6.2.1What platform does your issue occur on? (android/ios/both) Jest
Describe your issue as precisely as possible : 1) Steps to reproduce the issue or to explain in which case you get the issue
I was able to install and properly use the Pdf component in my application. However, when I tried to run a snapshot test with a mocked pdf file I got the error
TypeError: Cannot read property 'supportPDFKit' of undefined
. After some research, I found that this usually happens when the library is not properly linked in iOS or Android, but they are linked and the error only happens during the jest tests. Any idea what could cause it?2) Interesting
logs
Show us the code you are using?