-
Notifications
You must be signed in to change notification settings - Fork 0
Add i18n formatted messages / translations #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
| import { I18nProvider } from '@kbn/i18n/react'; | ||
| import { IntlProvider } from 'react-intl'; | ||
|
|
||
| const intlProvider = new IntlProvider({ locale: 'en', messages: {} }, {}); | ||
| const { intl } = intlProvider.getChildContext(); | ||
|
|
||
| /** | ||
| * This helper shallow wraps a component with react-intl's <I18nProvider> which | ||
| * fixes "Could not find required `intl` object" console errors when running tests | ||
| * | ||
| * Example usage (should be the same as shallow()): | ||
| * | ||
| * const wrapper = shallowWithIntl(<Component />); | ||
| */ | ||
| export const shallowWithIntl = children => { | ||
| return shallow(<I18nProvider>{children}</I18nProvider>, { | ||
| context: { intl }, | ||
| childContextTypes: { intl }, | ||
| }) | ||
|
Comment on lines
+24
to
+27
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this, you get a bunch of these console "errors" when running tests (even though the tests themselves pass): |
||
| .childAt(0) | ||
| .dive() | ||
| .shallow(); | ||
|
Comment on lines
+28
to
+30
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns the underlying I had to do this a bunch on older projects for HOC wrappers, I can 10000% say I don't miss it 😄 |
||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick note: I grabbed this from https://stackoverflow.com/questions/37021217/injecting-react-intl-object-into-mounted-enzyme-components-for-testing which seems to work pretty alright.