In the process of developing my Android app, I encountered a need to read NFC tags. To accomplish this task, I decided to utilize the react-native-nfc-manager
library. However, during my implementation, I faced two perplexing issues that have left me stumped.
- Firstly, what is the actual functionality of the
nfcManager.start()
function? Strangely, even when I removed it from the top of the method, my app seemed to still work fine. Upon further investigation, any attempts to check the promise's return value only resulted inundefined
. - Secondly, in an effort to test the page, I attempted to mock the
nfcManager
. However, I consistently ran into errors such as
orTypeError: _reactNativeNfcManager.default.start is not a function
, among others, for all interface functions.TypeError: _reactNativeNfcManager.default.isSupported is not a function
To replicate these errors and perform testing, I employed the following code:
const mockNfcManager = jest.fn();
jest.mock("react-native-nfc-manager", ()=>({ NfcManagerModule: { start: mockNfcManager, }, }));
Following this setup, I proceeded to render the component and verify if
expect(mockedNavigate).toHaveBeenCalled()
.