react-native-navigation-mock-render

0.1.1 • Public • Published

react-native-navigation-mock-render

NPM Version Build Status MIT License PRs Welcome

Work in progress, stay tuned.

Thin node.js mock of wix/react-native-navigation that makes it possible to write fast integration test including:

  • rendering of screens
  • life cycle methods
  • navigation between screens

Uses:

Prerequisite

  • react-native >= 0.49
  • react >= 16.0.0

Example usage with Jest

yarn add --dev react-native-navigation-mock-render jsdom@^11.5.1 enzyme@^3.3.0 enzyme-adapter-react-16@^1.1.1 react-native-mock-render@^0.0.19
 
/* @flow */
import { Navigation } from 'react-native-navigation'
import 'react-native-navigation-mock-render/lib/setup-enzyme-environment'
import { getEnzymeAppWrapper } from 'react-native-navigation-mock-render/lib/platform'
 
import { IntroScreen } from '../screens/intro'
import startApplication from '../index'
 
jest.mock('react-native-navigation/src/deprecated/platformSpecificDeprecated', () =>
  // $FlowFixMe: Jest adds requireActual
  require.requireActual('react-native-navigation-mock-render/lib/platform')
)
 
jest.mock('react-native-navigation/src/ScreenVisibilityListener', () =>
  // $FlowFixMe: Jest adds requireActual
  require.requireActual(
    'react-native-navigation-mock-render/lib/ScreenVisibilityListener'
  )
)
 
const wrapper = getEnzymeAppWrapper()
 
export const flushAllPromises = (): Promise<void> =>
  new Promise(resolve => setImmediate(resolve))
 
describe('app integration test', () => {
 
  it('shows authentication screen after stepping through intro', async () => {
    startApplication()
 
    await flushAllPromises()
 
    let screenId = await Navigation.getCurrentlyVisibleScreenId()
    expect(screenId).toEqual('MyApp.Intro')
 
    const introInstance = wrapper
      .find(IntroScreen)
      .first()
      .instance()
 
    introInstance.onAcceptTermsPressed()
 
    await flushAllPromises()
 
    screenId = await Navigation.getCurrentlyVisibleScreenId()
    expect(screenId).toEqual('MyApp.MainScreen')
  })
})

Limitations

Still early stages. First focus is apps using startSingleScreenApp.

Besides:

  • not all ScreenVisibilityListener have been implemented
  • not all Navigation methods have been implemented (e.g. startTabBasedApp, showContextualMenu)

Contributing

To get started, run:

yarn

When developing:

yarn run lint

License

MIT

Package Sidebar

Install

npm i react-native-navigation-mock-render

Weekly Downloads

4

Version

0.1.1

License

MIT

Last publish

Collaborators

  • skovhus