import { IntlMessageFormat } from 'intl-messageformat';
import { wrapValues } from 'intl-messageformat-html';
const interpolationValues = {
firstName: 'John',
lastName: 'Doe',
age: 47,
};
createTest(
'MessageFormat sanity',
'String to string',
'String to string',
);
createTest(
'Interpolation sanity',
'Hello {firstName}!',
'Hello John!',
);
createTest(
'List',
'
OneTwo',
'OneTwo',
);
createTest(
'Nested list',
'',
'',
);
createTest(
'Link',
'For more information https://cnn.comvisit CNN.',
'For more information visit CNN.',
);
function createTest(
name: string,
input: string,
expected: string,
classNames?: string[]
) {
test(name, () => {
const actual = new IntlMessageFormat(input)
.format(
wrapValues(interpolationValues, classNames)
);
expect(actual).toBe(expected);
})
}