Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
intl-enzyme-test-helper.ts
import React from 'react';
import { IntlProvider, intlShape } from 'react-intl';
import { mount, render, shallow } from 'enzyme';
const messages = {}; // en.json
const intlProvider = new IntlProvider({ locale: 'en', messages, onError: () => '' }, {});
const { intl } = intlProvider.getChildContext();
function nodeWithIntlProp(node) {
return React.cloneElement(node, { intl });
}
export function shallowWithIntl(node) {
return shallow(nodeWithIntlProp(node), { context: { intl } });
}
export function mountWithIntl(node) {
return mount(nodeWithIntlProp(node), {
context: { intl },
childContextTypes: { intl: intlShape }
});
}
export function renderWithIntl(node) {
return render(nodeWithIntlProp(node), {
context: { intl },
childContextTypes: { intl: intlShape }
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment