From 143a18807e0fa88e95711559c38ca9c63ca69ffa Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 24 Mar 2019 12:15:06 -0400 Subject: [PATCH] Adding mocking tools for components --- src/__mocks__/component-mock.js | 17 +++++++++++++++++ src/__mocks__/react-i18next.js | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 src/__mocks__/component-mock.js create mode 100644 src/__mocks__/react-i18next.js diff --git a/src/__mocks__/component-mock.js b/src/__mocks__/component-mock.js new file mode 100644 index 0000000..ba6ef4c --- /dev/null +++ b/src/__mocks__/component-mock.js @@ -0,0 +1,17 @@ +const React = require('react'); + +const buildMock = component => { + const componentName = component.displayName || component.name || 'Component'; + const Mock = ({ children, ...props }) => ( + { children } + ); + Mock.propTypes = component.propTypes; + return Mock; +}; + +module.exports = path => { + const actual = jest.requireActual(path).default; + return buildMock(actual); +}; + +module.exports.buildMock = buildMock; diff --git a/src/__mocks__/react-i18next.js b/src/__mocks__/react-i18next.js new file mode 100644 index 0000000..14d998c --- /dev/null +++ b/src/__mocks__/react-i18next.js @@ -0,0 +1,6 @@ +const reactI18next = jest.requireActual('react-i18next'); + +module.exports = { + ...reactI18next, + Trans: require('__mocks__/component-mock').buildMock(reactI18next.Trans) +};