1

I am developing an android app that requires to read nfc tags, so I am using the react-native-nfc-manager. However, I have come across two issues that I could not figure out at all.

  • What does the nfcManager.start() function actually do? I realized that the app was working even if I remove it from the top of the method. If I try to check what the promise returns, it returns undefined
  • I want to test the page, so I try to mock nfcManager. However, I always get this issue TypeError: _reactNativeNfcManager.default.start is not a function or TypeError: _reactNativeNfcManager.default.isSupported is not a function etc with all the functions of the interface.

What I try to do and get the above mentioned errors is

const mockNfcManager = jest.fn();

jest.mock("react-native-nfc-manager", ()=>({ NfcManagerModule: { start: mockNfcManager, }, }));

and then render the component and check if expect(mockedNavigate).toHaveBeenCalled()

1 Answers1

0
nfcManager
  .start({
    onSessionClosedIOS: () => {},
  })
  .then(result => {})
  .catch(error => {
    console.warn('device does not support nfc!');
  });
Umer Arain
  • 17
  • 2