Skip to content

CoorpAcademy/react-native-mock-render

 
 

Repository files navigation

another fork ?

Root App doesn't maintain its fork anymore, and we at Coorpacademy need to update Mocks as React Native goes further.

react-native-mock-render

A fork of react-native-mock that renders components

Requirements

  • Node.js 16+
  • The latest version of react-native

Installation

npm i @coorpacademy/react-native-mock-render --save-dev
/* file-that-runs-before-all-of-my-tests.js */

// This will mutate `react-native`'s require cache with `react-native-mock`'s.
require('@coorpacademy/react-native-mock-render/mock')(); // <-- side-effects!!!

External libs

to mock optional external libs, use:

require('@coorpacademy/react-native-mock-render/mock')({
  externalLibs: [
    {
      name: 'react-native-lib-with-many-exports',
      exports: ['ComponentA', 'ComponentB', 'ComponentC']
    },
    {
      name: 'react-native-lib-with-default-export',
      exports: 'ImportName'
    },
    {
      name: 'react-native-modal',
      exports: 'Modal'
    }
  ]
});

Jest

--> jest mocking https://github.com/facebook/react-native/blob/main/jest/mockComponent.js

Jest doesn't support require.cache, so the correct way to do the mocking is using jest.mock('react-native', () => require('react-native-mock-render'), {virtual: true}) in your tests setup file.

Why?

We wanted to be able deeply render React Native components in our integration tests and already used react-native-mock.

Contributors

react-native-mock Core Contributors

About

a fork of react-native-mock that renders

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%