Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skovhus/react-native-navigation-mock-render
Enzyme render mock of wix/react-native-navigation – super fast integration test! 🚀
https://github.com/skovhus/react-native-navigation-mock-render
enzyme jest react-native testing
Last synced: 27 days ago
JSON representation
Enzyme render mock of wix/react-native-navigation – super fast integration test! 🚀
- Host: GitHub
- URL: https://github.com/skovhus/react-native-navigation-mock-render
- Owner: skovhus
- License: mit
- Created: 2018-01-14T10:44:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T11:47:09.000Z (almost 7 years ago)
- Last Synced: 2024-04-24T21:21:27.867Z (7 months ago)
- Topics: enzyme, jest, react-native, testing
- Language: JavaScript
- Size: 266 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
react-native-navigation-mock-render
[![NPM Version](https://img.shields.io/npm/v/react-native-navigation-mock-render.svg?style=flat)](https://www.npmjs.com/package/react-native-navigation-mock-render)
[![Build Status](https://travis-ci.org/skovhus/react-native-navigation-mock-render.svg?branch=master)](https://travis-ci.org/skovhus/react-native-navigation-mock-render)
[![MIT License](https://img.shields.io/npm/l/react-native-navigation-mock-render.svg?style=flat-square)](https://github.com/skovhus/react-native-navigation-mock-render/blob/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)**Work in progress, stay tuned.**
Thin node.js mock of [wix/react-native-navigation](https://github.com/wix/react-native-navigation) that makes it possible to write fast integration test including:
- rendering of screens
- life cycle methods
- navigation between screensUses:
- [react-native-mock-render](https://github.com/Root-App/react-native-mock-render)
- [enzyme](https://github.com/airbnb/enzyme)
- [jsdom](https://github.com/tmpvar/jsdom)## Prerequisite
- `react-native` >= 0.49
- `react` >= 16.0.0## Example usage with Jest
```shell
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
```Besides you need a version of `react-dom` matching your version of `react`.
```javascript
import { Navigation } from 'react-native-navigation'
import 'react-native-navigation-mock-render/setup/enzyme-environment'
import { getEnzymeAppWrapper } from 'react-native-navigation-mock-render/mock/platform'import { IntroScreen } from '../screens/Intro'
import startApp from '../index'jest.mock('react-native-navigation/src/deprecated/platformSpecificDeprecated', () =>
require.requireActual('react-native-navigation-mock-render/mock/platform')
)jest.mock('react-native-navigation/src/ScreenVisibilityListener', () =>
require.requireActual(
'react-native-navigation-mock-render/mock/ScreenVisibilityListener'
)
)const wrapper = getEnzymeAppWrapper()
const flushAllPromises = () =>
new Promise(resolve => setImmediate(resolve))describe('app integration test', () => {
it('shows main screen after stepping through intro', async () => {
startApp()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')
})
})
```See more inside the `example/__tests__` folder.
## 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