Closed PanosPapad closed 1 year ago
This worked for me at the top level of my test scripts. Alternatively you could also place this in a __mocks__
folder in your root directory and include it in your setupFiles
in jest.config.js
jest.mock('react-native-nfc-manager', () => ({
start: () => Promise.resolve(),
}));
Hi @PanosPapad , sorry for the late response.
The start()
function is simply used to initialize the native layer.
Regarding the mock
, I think @dylanclements 's suggestion should work:
jest.mock('react-native-nfc-manager', () => ({
start: () => Promise.resolve(),
isSupported: () => Promise.resolve(false), // bypass NFC feature when running test cases
}));
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
Hello,
I am developing an android app that requires to read nfc tags, so I am using this library. However, I have come across two issues that I could not figure out at all.
nfcManager.start()
function do? I realized that the app was working even if I remove it from the top of the method.nfcManager
. However, I always get this issueTypeError: _reactNativeNfcManager.default.start is not a function
orTypeError: _reactNativeNfcManager.default.isSupported is not a function
etc with all the functions of the interface. What I try to do isconst mockNfcManager = jest.fn();
jest.mock("react-native-nfc-manager", ()=>({ NfcManagerModule: { start: mockNfcManager, }, }));
and then render the component and check if
expect(mockedNavigate).toHaveBeenCalled()
Sorry for the long message, but I saw you are pretty responsive in the issues of this library, and also I have not seen anyone mentioning these issues anywhere, so I was hoping to solve this issue here :) Thanks a lot!