Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import React from 'react';
  2. import { IntlProvider, intlShape } from 'react-intl';
  3. import { mount, render, shallow } from 'enzyme';
  4.  
  5. const messages = {}; // en.json
  6.  
  7. const intlProvider = new IntlProvider({ locale: 'en', messages, onError: () => '' }, {});
  8. const { intl } = intlProvider.getChildContext();
  9.  
  10. function nodeWithIntlProp(node) {
  11. return React.cloneElement(node, { intl });
  12. }
  13.  
  14. export function shallowWithIntl(node) {
  15. return shallow(nodeWithIntlProp(node), { context: { intl } });
  16. }
  17.  
  18. export function mountWithIntl(node) {
  19. return mount(nodeWithIntlProp(node), {
  20. context: { intl },
  21. childContextTypes: { intl: intlShape }
  22. });
  23. }
  24.  
  25. export function renderWithIntl(node) {
  26. return render(nodeWithIntlProp(node), {
  27. context: { intl },
  28. childContextTypes: { intl: intlShape }
  29. });
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement