If you want to test native modules, I suggest the following:
1. E2E Tests
Node.js standalone cannot interpret native modules. If you want to test native modules in the context of your app, you want to create e2e tests using appium/webdriverio instead of writing unit tests with mocha.
With this, you actually start an emulator with your app installed.
Resources:
- http://appium.io/docs/en/about-appium/intro/?lang=de
- https://medium.com/jetclosing-engineering/react-native-device-testing-w-appium-node-and-aws-device-farm-295081129790
- https://medium.com/swlh/automation-testing-using-react-native-and-appium-on-ubuntu-ddfddc0c29fe
- https://webdriver.io/docs/api/appium.html
2. Unit Tests
If you want to write unit tests for your native module, write them in the Language the Native Module is written in
Resources:
- https://www.swiftbysundell.com/basics/unit-testing/
- https://junit.org/junit5/
- https://developer.apple.com/documentation/xctest
- https://cmake.org/cmake/help/latest/manual/ctest.1.html
Other than that, you have to mock the modules.
- https://jestjs.io/docs/en/mock-functions
- https://sinonjs.org/releases/latest/mocks/
- https://www.npmjs.com/package/mock-require