react-native-integration-tests v0.1.5
react-native-integration-tests
Deprecated in favor of react-native-in-app-testing
A React Native component for testing native modules integration directly inside the existing app.
Usage
npm install react-native-integration-tests -D
Import RNIntegrationTests module and insert the imported component into any another React Native component and specify required props:
import RNIntegrationTests from 'react-native-integration-tests' <View> <RNIntegrationTests testFunctions={ arrayOfTestFunctions } passedTitle="Passed" failedTitle="Failed" coverageText="Coverage of connected modules" /> </View>
How to write tests
At first import it
and connectModule
functions and connect native modules which are supposed to test.
import RNIntegrationTests from 'react-native-integration-tests'
const { it, connectModule } = RNIntegrationTests
const SomeNativeModule = connectModule( NativeModules.SomeNativeModule )
Test functions have to be inside an array which is passed as a prop to RNIntegrationTests component.
Each of passed test functions has to return a promise and the test runner shows results in dependency of the promise state (fulfilled or rejected).
Example with chai assertion library:
For correct work of the chai library may need to install buffer as a dev dependency.
import { NativeModules } from 'react-native'
import RNIntegrationTests from 'react-native-integration-tests'
const { it, connectModule } = RNIntegrationTests
import { expect } from 'chai'
const SomeNativeModule = connectModule( NativeModules.SomeNativeModule )
const testFunctions = [
it( 'some method should return an array', () => {
return new Promise( ( resolve, reject ) => {
SomeNativeModule.someMethod( ( response ) => {
try {
expect( response ).to.be.instanceof( Array )
resolve()
} catch ( error ) {
reject( error )
}
}
)
} )
} )
]