2019-07-31 17:35:57 -04:00
|
|
|
/*
|
|
|
|
* Helpers for using enzyme and react-test-renderer with react-intl
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
import renderer from 'react-test-renderer';
|
2023-01-06 15:55:16 -05:00
|
|
|
import {createIntl, IntlProvider} from 'react-intl';
|
2019-07-31 17:35:57 -04:00
|
|
|
import {mount, shallow} from 'enzyme';
|
2023-01-06 15:55:16 -05:00
|
|
|
import intlShape from '../../src/lib/intl-shape';
|
2019-07-31 17:35:57 -04:00
|
|
|
|
2023-10-24 14:22:28 -04:00
|
|
|
const shallowWithIntl = (node, {context} = {}) => shallow(
|
|
|
|
node,
|
|
|
|
{
|
|
|
|
context: Object.assign({}, context),
|
|
|
|
wrappingComponent: IntlProvider,
|
|
|
|
wrappingComponentProps: {
|
|
|
|
locale: 'en',
|
|
|
|
messages: {}
|
2023-01-06 15:55:16 -05:00
|
|
|
}
|
2023-10-24 14:22:28 -04:00
|
|
|
}
|
|
|
|
).dive();
|
2019-07-31 17:35:57 -04:00
|
|
|
|
2023-01-06 15:55:16 -05:00
|
|
|
const mountWithIntl = (node, {context, childContextTypes} = {}) => {
|
|
|
|
const intl = createIntl({locale: 'en', messages: {}});
|
|
|
|
return mount(
|
|
|
|
node,
|
|
|
|
{
|
|
|
|
context: Object.assign({}, context, {intl}),
|
|
|
|
childContextTypes: Object.assign({}, {intl: intlShape}, childContextTypes),
|
|
|
|
wrappingComponent: IntlProvider,
|
|
|
|
wrappingComponentProps: {
|
|
|
|
locale: 'en',
|
|
|
|
messages: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2019-07-31 17:35:57 -04:00
|
|
|
|
|
|
|
// react-test-renderer component for use with snapshot testing
|
|
|
|
const componentWithIntl = (children, props = {locale: 'en'}) => renderer.create(
|
2023-02-22 09:28:58 -05:00
|
|
|
<IntlProvider
|
|
|
|
textComponent="span"
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</IntlProvider>
|
2019-07-31 17:35:57 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
export {
|
|
|
|
componentWithIntl,
|
|
|
|
shallowWithIntl,
|
|
|
|
mountWithIntl
|
|
|
|
};
|