Created
October 2, 2019 13:16
-
-
Save alanhe421/93445ee840866586dac30a67cf4f6822 to your computer and use it in GitHub Desktop.
intl-enzyme-test-helper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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