Adding mocking tools for components
This commit is contained in:
parent
4fd02d661d
commit
143a18807e
17
src/__mocks__/component-mock.js
Normal file
17
src/__mocks__/component-mock.js
Normal 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
6
src/__mocks__/react-i18next.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const reactI18next = jest.requireActual('react-i18next');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...reactI18next,
|
||||||
|
Trans: require('__mocks__/component-mock').buildMock(reactI18next.Trans)
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user