Adding mocking tools for components

This commit is contained in:
Jeff Avallone 2019-03-24 12:15:06 -04:00
parent 4fd02d661d
commit 143a18807e
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,17 @@
const React = require('react');
const buildMock = component => {
const componentName = component.displayName || component.name || 'Component';
const Mock = ({ children, ...props }) => (
<span data-component={ componentName } { ...props }>{ children }</span>
);
Mock.propTypes = component.propTypes;
return Mock;
};
module.exports = path => {
const actual = jest.requireActual(path).default;
return buildMock(actual);
};
module.exports.buildMock = buildMock;

6
src/__mocks__/react-i18next.js vendored Normal file
View File

@ -0,0 +1,6 @@
const reactI18next = jest.requireActual('react-i18next');
module.exports = {
...reactI18next,
Trans: require('__mocks__/component-mock').buildMock(reactI18next.Trans)
};