Socket
Book a DemoInstallSign in
Socket

react-native-navigation-mock-render

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-navigation-mock-render

Enzyme render mock of wix/react-native-navigation

0.1.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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

Keywords

react

FAQs

Package last updated on 14 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.