-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.test.ts
47 lines (40 loc) · 1.49 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable @typescript-eslint/no-var-requires */
import '@formatjs/intl-getcanonicallocales/polyfill';
import {DisplayNames} from '../';
import * as en from './locale-data/en.json';
import * as zh from './locale-data/zh.json';
DisplayNames.__addLocaleData(en, zh);
describe('.of()', () => {
it('accepts case-insensitive language code with region subtag', () => {
expect(new DisplayNames('zh', {type: 'language'}).of('zh-hANs-sG')).toBe(
'简体中文(新加坡)'
);
});
it('accepts case-insensitive currency code', () => {
expect(
new DisplayNames('en-US', {type: 'currency', style: 'long'}).of('cNy')
).toBe('Chinese Yuan');
});
it('preserves unrecognized region subtag in language code when fallback option is code', () => {
expect(
new DisplayNames('zh', {type: 'language', fallback: 'code'}).of(
'zh-Hans-Xy'
)
).toBe('简体中文(XY)');
});
describe('with fallback set to "none"', () => {
it('returns undefined when called with language code that has unrecognized region subtag', () => {
expect(
new DisplayNames('zh', {type: 'language', fallback: 'none'}).of(
'zh-Hans-XY'
)
).toBe(undefined);
});
it('returns undefined when called with language code that valid region subtag but invalid language subtag', () => {
expect(
new DisplayNames('zh', {type: 'language', fallback: 'none'}).of('xx-CN')
).toBe(undefined);
});
});
});
// TODO: add snapshot tests