Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 1x 1x 1x 6x 6x | /** * Components using the react-intl module require access to the intl context. * This is not available when mounting single components in Enzyme. * These helper functions aim to address that and wrap a valid, * English-locale intl context around them. */ import React from 'react'; import { IntlProvider, intlShape } from 'react-intl'; import { mount, shallow } from 'enzyme'; // You can pass your messages to the IntlProvider. Optional: remove if unneeded. const messages = require('../../src/components/locale'); // en.json // Create the IntlProvider to retrieve context for wrapping around. const intlProvider = new IntlProvider({ locale: 'en', messages: messages.en }, {}); const { intl } = intlProvider.getChildContext(); /** * When using React-Intl `injectIntl` on components, props.intl is required. */ function nodeWithIntlProp(node) { return React.cloneElement(node, { intl }); } export function shallowWithIntl(node, { context, ...additionalOptions } = {}) { return shallow( nodeWithIntlProp(node), { context: Object.assign({}, context, {intl}), ...additionalOptions, } ); } export function mountWithIntl(node, { context, childContextTypes, ...additionalOptions } = {}) { return mount( nodeWithIntlProp(node), { context: Object.assign({}, context, {intl}), childContextTypes: Object.assign({}, { intl: intlShape }, childContextTypes), ...additionalOptions, } ); } |