Skip to main content
Version: 4.0.x

Jest mock usage

To make testing with Jest easier, library provides mocked implementation that can be integrated in two ways:

Using mock in __mocks__ directory

  1. Create __mocks__/react-native-avoid-softinput file.
  2. Inside created file paste following lines:
const mock = require('react-native-avoid-softinput/jest/mock');

/**
* If needed, override mock like so:
*
* module.exports = Object.assign(mock, { useSoftInputState: jest.fn(() => ({ isSoftInputShown: true, softInputHeight: 300 })) });
*/

module.exports = mock;

Using mock in Jest setup file

  1. Create Jest setup file, unless there is already one, and link it in jest config
  2. Inside Jest setup file add following lines:
jest.mock('react-native-avoid-softinput', () => {
const mock = require('react-native-avoid-softinput/jest/mock');

/**
* If needed, override mock like so:
*
* return Object.assign(mock, { useSoftInputState: jest.fn(() => ({ isSoftInputShown: true, softInputHeight: 300 })) });
*/

return mock;
});