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
- Create
__mocks__/react-native-avoid-softinput
file. - 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
- Create Jest setup file, unless there is already one, and link it in jest config
- 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;
});