mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 23:27:54 -05:00
40 lines
1.2 KiB
React
40 lines
1.2 KiB
React
|
/*
|
||
|
* Helpers for using enzyme and react-test-renderer with react-intl
|
||
|
* Directly from https://github.com/yahoo/react-intl/wiki/Testing-with-React-Intl
|
||
|
*/
|
||
|
import React from 'react';
|
||
|
import renderer from 'react-test-renderer';
|
||
|
import {IntlProvider, intlShape} from 'react-intl';
|
||
|
import {mount, shallow} from 'enzyme';
|
||
|
|
||
|
const intlProvider = new IntlProvider({locale: 'en'}, {});
|
||
|
const {intl} = intlProvider.getChildContext();
|
||
|
|
||
|
const nodeWithIntlProp = node => React.cloneElement(node, {intl});
|
||
|
|
||
|
const shallowWithIntl = (node, {context} = {}) => shallow(
|
||
|
nodeWithIntlProp(node),
|
||
|
{
|
||
|
context: Object.assign({}, context, {intl})
|
||
|
}
|
||
|
);
|
||
|
|
||
|
const mountWithIntl = (node, {context, childContextTypes} = {}) => mount(
|
||
|
nodeWithIntlProp(node),
|
||
|
{
|
||
|
context: Object.assign({}, context, {intl}),
|
||
|
childContextTypes: Object.assign({}, {intl: intlShape}, childContextTypes)
|
||
|
}
|
||
|
);
|
||
|
|
||
|
// react-test-renderer component for use with snapshot testing
|
||
|
const componentWithIntl = (children, props = {locale: 'en'}) => renderer.create(
|
||
|
<IntlProvider {...props}>{children}</IntlProvider>
|
||
|
);
|
||
|
|
||
|
export {
|
||
|
componentWithIntl,
|
||
|
shallowWithIntl,
|
||
|
mountWithIntl
|
||
|
};
|