@shopify/polaris
Version:
Shopify’s product component library
24 lines (23 loc) • 1.14 kB
JavaScript
import { translate } from '../I18n';
describe('translate()', () => {
it('returns a simple string value in the translation dictionary', () => {
expect(translate('foo', { foo: 'bar' })).toBe('bar');
});
it('returns a nested string value in the translation dictionary', () => {
expect(translate('foo.bar.baz', { foo: { bar: { baz: 'qux' } } })).toBe('qux');
});
it('returns an empty string when no match is found', () => {
expect(translate('foo.bar.baz', { foo: { bar: 'baz' } })).toBe('');
});
describe('replacements', () => {
function translateWithReplacements(id, replacements) {
return translate('value', { value: id }, replacements);
}
it('uses replacements', () => {
expect(translateWithReplacements('foo {next}', { next: 'bar' })).toBe('foo bar');
});
it('throws an error for a missing replacement', () => {
expect(() => translateWithReplacements('foo {next}', { notNext: 'bar' })).toThrow(`No replacement found for key 'next'. The following replacements were passed: 'notNext'`);
});
});
});