strapi/test/config/front/testUtils/mountWithIntl.js

20 lines
585 B
JavaScript
Raw Normal View History

2019-04-23 15:18:57 +02:00
import React from 'react';
import { mount } from 'enzyme';
import PropTypes from 'prop-types';
import { IntlProvider, intlShape } from 'react-intl';
const mountWithIntl = (componentToMount, pluginTrads, context = {}) => {
const intlProvider = new IntlProvider(
{ locale: 'en', messages: pluginTrads },
{},
);
const { intl } = intlProvider.getChildContext();
return mount(React.cloneElement(componentToMount, { intl }), {
context: { intl, ...context },
childContextTypes: { intl: intlShape, emitEvent: PropTypes.func },
});
};
export default mountWithIntl;