Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// See https://github.com/yahoo/react-intl/wiki/Testing-with-React-Intl#enzyme
/**
* 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 } from 'react-intl'
import { mount, shallow } from 'enzyme'
import messages from '@zap/translations/en.json'
import { intlShape } from '@zap/i18n'
// Create the IntlProvider to retrieve context for wrapping around.
const intlProvider = new IntlProvider({ locale: 'en', messages }, {})
const { intl } = intlProvider.getChildContext()
// nodeWithIntlProp - When using React-Intl `injectIntl` on components, props.intl is required.
const nodeWithIntlProp = node => {
return React.cloneElement(node, { intl })
}
export const shallowWithIntl = (node, { context, ...additionalOptions } = {}) => {
return shallow(nodeWithIntlProp(node), {
context: Object.assign({}, context, { intl }),
...additionalOptions,
})
}
export const mountWithIntl = (node, { context, childContextTypes, ...additionalOptions } = {}) => {
return mount(nodeWithIntlProp(node), {
* Based on: https://gist.github.com/mirague/c05f4da0d781a9b339b501f1d5d33c37/
*
* 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';
// Create the IntlProvider to retrieve context for wrapping around.
// NOTE: Phantomjs requires usage of `var`
var intlProvider = new IntlProvider({ locale: 'en' }, {}); // eslint-disable-line
var intl = intlProvider.getChildContext(); // eslint-disable-line
/**
* When using React-Intl `injectIntl` on components, props.intl is required.
*/
function nodeWithIntlProp(node) {
return React.cloneElement(node, intl);
}
/**
* Export these methods.
*/
export function shallowWithIntl(node) {
return shallow(nodeWithIntlProp(node), { context: intl });
}
/**
* 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('../translations/en') // en.json
// Create the IntlProvider to retrieve context for wrapping around.
const intlProvider = new IntlProvider({ locale: 'en', messages }, {})
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
}
* 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.
*
* https://github.com/yahoo/react-intl/wiki/Testing-with-React-Intl
*/
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('../../assets/locales/en/main.json')
// Create the IntlProvider to retrieve context for wrapping around.
const intlProvider = new IntlProvider({ locale: 'en', messages }, {})
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
}
/**
* 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, render } from 'enzyme'
// You can pass your messages to the IntlProvider. Optional: remove if unneeded.
import messages from '../lang/en'
// Create the IntlProvider to retrieve context for wrapping around.
const intlProvider = new IntlProvider({ locale: 'en', messages }, {})
export const { intl } = intlProvider.getChildContext()
/**
* When using React-Intl `injectIntl` on components, props.intl is required.
*/
const nodeWithIntlProp = node => {
return React.cloneElement(node, { intl })
}
export const shallowWithIntl = node => {
return shallow(nodeWithIntlProp(node), { context: { intl } })
}
export const mountWithIntl = node => {
return mount(nodeWithIntlProp(node), {
context: { intl },
injectIntl,
FormattedMessage,
FormattedHTMLMessage,
FormattedDate,
FormattedTime,
FormattedRelative,
FormattedNumber,
FormattedPlural,
IntlProvider
} from "react-intl";
import type { IntlShape, MessageDescriptor } from "react-intl";
import { it, describe } from "flow-typed-test";
intlShape({ foo: "bar" }, "propName", "TestComponentName");
// $ExpectError number. This type is incompatible with void
const result1: number = intlShape(
{ foo: "bar" },
"propName",
"TestComponentName"
);
const localeData = {
locale: "fi",
testKey: { foo: "bar" },
testKey2: { baz: "buu" }
};
addLocaleData(localeData);
// $ExpectError number. This type is incompatible with void
const resultLocaleData: number = addLocaleData(localeData);
const messages = {
messagekey1: {
intlShape,
addLocaleData,
defineMessages,
injectIntl,
FormattedMessage,
FormattedHTMLMessage,
FormattedDate,
FormattedTime,
FormattedRelative,
FormattedNumber,
FormattedPlural,
IntlProvider
} from "react-intl";
import type { IntlShape, MessageDescriptor, IntlInjectedComponentClass } from "react-intl";
intlShape({ foo: "bar" }, "propName", "TestComponentName");
// $ExpectError number. This type is incompatible with void
const result1: number = intlShape(
{ foo: "bar" },
"propName",
"TestComponentName"
);
const localeData = {
locale: "fi",
testKey: { foo: "bar" },
testKey2: { baz: "buu" }
};
addLocaleData(localeData);
// $ExpectError number. This type is incompatible with void
const resultLocaleData: number = addLocaleData(localeData);
defineMessages,
injectIntl,
FormattedMessage,
FormattedHTMLMessage,
FormattedDate,
FormattedTime,
FormattedRelative,
FormattedNumber,
FormattedPlural,
IntlProvider
} from "react-intl";
import type { IntlShape, MessageDescriptor, IntlInjectedComponentClass } from "react-intl";
intlShape({ foo: "bar" }, "propName", "TestComponentName");
// $ExpectError number. This type is incompatible with void
const result1: number = intlShape(
{ foo: "bar" },
"propName",
"TestComponentName"
);
const localeData = {
locale: "fi",
testKey: { foo: "bar" },
testKey2: { baz: "buu" }
};
addLocaleData(localeData);
// $ExpectError number. This type is incompatible with void
const resultLocaleData: number = addLocaleData(localeData);
const messages = {
messagekey1: {
defineMessages,
injectIntl,
FormattedMessage,
FormattedHTMLMessage,
FormattedDate,
FormattedTime,
FormattedRelative,
FormattedNumber,
FormattedPlural,
IntlProvider
} from "react-intl";
import type { IntlShape, MessageDescriptor } from "react-intl";
intlShape({ foo: "bar" }, "propName", "TestComponentName");
// $ExpectError number. This type is incompatible with void
const result1: number = intlShape(
{ foo: "bar" },
"propName",
"TestComponentName"
);
const localeData = {
locale: "fi",
testKey: { foo: "bar" },
testKey2: { baz: "buu" }
};
addLocaleData(localeData);
// $ExpectError number. This type is incompatible with void
const resultLocaleData: number = addLocaleData(localeData);
const messages = {
messagekey1: {
defineMessages,
injectIntl,
FormattedMessage,
FormattedHTMLMessage,
FormattedDate,
FormattedTime,
FormattedRelative,
FormattedNumber,
FormattedPlural,
IntlProvider
} from "react-intl";
import type { IntlShape } from "react-intl";
intlShape({ foo: "bar" }, "propName", "TestComponentName");
// $ExpectError number. This type is incompatible with void
const result1: number = intlShape(
{ foo: "bar" },
"propName",
"TestComponentName"
);
const localeData = {
locale: "fi",
testKey: { foo: "bar" },
testKey2: { baz: "buu" }
};
addLocaleData(localeData);
// $ExpectError number. This type is incompatible with void
const resultLocaleData: number = addLocaleData(localeData);
const messages = {
messagekey1: {