@ -12,35 +12,50 @@ import localeEnExtra from '@angular/common/locales/extra/en';
|
||||
import localeHu from '@angular/common/locales/hu';
|
||||
import localeSr from '@angular/common/locales/sr';
|
||||
import localeTh from '@angular/common/locales/th';
|
||||
import {isDate, toDate, formatDate} from '@angular/common/src/i18n/format_date';
|
||||
import {ɵDEFAULT_LOCALE_ID, ɵunregisterLocaleData, ɵregisterLocaleData} from '@angular/core';
|
||||
import {formatDate, isDate, toDate} from '@angular/common/src/i18n/format_date';
|
||||
import {ɵDEFAULT_LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
|
||||
describe('Format date', () => {
|
||||
describe('toDate', () => {
|
||||
it('should support date', () => { expect(isDate(toDate(new Date()))).toBeTruthy(); });
|
||||
it('should support date', () => {
|
||||
expect(isDate(toDate(new Date()))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support int', () => { expect(isDate(toDate(123456789))).toBeTruthy(); });
|
||||
it('should support int', () => {
|
||||
expect(isDate(toDate(123456789))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support numeric strings',
|
||||
() => { expect(isDate(toDate('123456789'))).toBeTruthy(); });
|
||||
it('should support numeric strings', () => {
|
||||
expect(isDate(toDate('123456789'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support decimal strings',
|
||||
() => { expect(isDate(toDate('123456789.11'))).toBeTruthy(); });
|
||||
it('should support decimal strings', () => {
|
||||
expect(isDate(toDate('123456789.11'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support ISO string',
|
||||
() => { expect(isDate(toDate('2015-06-15T21:43:11Z'))).toBeTruthy(); });
|
||||
it('should support ISO string', () => {
|
||||
expect(isDate(toDate('2015-06-15T21:43:11Z'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should throw for empty string', () => { expect(() => toDate('')).toThrow(); });
|
||||
it('should throw for empty string', () => {
|
||||
expect(() => toDate('')).toThrow();
|
||||
});
|
||||
|
||||
it('should throw for alpha numeric strings',
|
||||
() => { expect(() => toDate('123456789 hello')).toThrow(); });
|
||||
it('should throw for alpha numeric strings', () => {
|
||||
expect(() => toDate('123456789 hello')).toThrow();
|
||||
});
|
||||
|
||||
it('should throw for NaN', () => { expect(() => toDate(Number.NaN)).toThrow(); });
|
||||
it('should throw for NaN', () => {
|
||||
expect(() => toDate(Number.NaN)).toThrow();
|
||||
});
|
||||
|
||||
it('should support ISO string without time',
|
||||
() => { expect(isDate(toDate('2015-01-01'))).toBeTruthy(); });
|
||||
it('should support ISO string without time', () => {
|
||||
expect(isDate(toDate('2015-01-01'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should throw for objects', () => { expect(() => toDate({} as any)).toThrow(); });
|
||||
it('should throw for objects', () => {
|
||||
expect(() => toDate({} as any)).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDate', () => {
|
||||
@ -49,7 +64,7 @@ describe('Format date', () => {
|
||||
let date: Date;
|
||||
|
||||
// Check the transformation of a date into a pattern
|
||||
function expectDateFormatAs(date: Date | string, pattern: any, output: string): void {
|
||||
function expectDateFormatAs(date: Date|string, pattern: any, output: string): void {
|
||||
expect(formatDate(date, pattern, ɵDEFAULT_LOCALE_ID))
|
||||
.toEqual(output, `pattern: "${pattern}"`);
|
||||
}
|
||||
@ -65,7 +80,9 @@ describe('Format date', () => {
|
||||
|
||||
afterAll(() => ɵunregisterLocaleData());
|
||||
|
||||
beforeEach(() => { date = new Date(2015, 5, 15, 9, 3, 1, 550); });
|
||||
beforeEach(() => {
|
||||
date = new Date(2015, 5, 15, 9, 3, 1, 550);
|
||||
});
|
||||
|
||||
it('should format each component correctly', () => {
|
||||
const dateFixtures: any = {
|
||||
@ -293,7 +310,7 @@ describe('Format date', () => {
|
||||
});
|
||||
|
||||
it('should remove bidi control characters',
|
||||
() => expect(formatDate(date, 'MM/dd/yyyy', ɵDEFAULT_LOCALE_ID) !.length).toEqual(10));
|
||||
() => expect(formatDate(date, 'MM/dd/yyyy', ɵDEFAULT_LOCALE_ID)!.length).toEqual(10));
|
||||
|
||||
it(`should format the date correctly in various locales`, () => {
|
||||
expect(formatDate(date, 'short', 'de')).toEqual('15.06.15, 09:03');
|
||||
|
@ -6,13 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {formatCurrency, formatNumber, formatPercent} from '@angular/common';
|
||||
import localeAr from '@angular/common/locales/ar';
|
||||
import localeEn from '@angular/common/locales/en';
|
||||
import localeEsUS from '@angular/common/locales/es-US';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import localeAr from '@angular/common/locales/ar';
|
||||
import {formatCurrency, formatNumber, formatPercent} from '@angular/common';
|
||||
import {ɵDEFAULT_LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {ɵDEFAULT_LOCALE_ID, ɵunregisterLocaleData, ɵregisterLocaleData} from '@angular/core';
|
||||
|
||||
describe('Format number', () => {
|
||||
beforeAll(() => {
|
||||
@ -44,8 +44,9 @@ describe('Format number', () => {
|
||||
});
|
||||
|
||||
describe('transform with custom locales', () => {
|
||||
it('should return the correct format for es-US',
|
||||
() => { expect(formatNumber(9999999.99, 'es-US', '1.2-2')).toEqual('9,999,999.99'); });
|
||||
it('should return the correct format for es-US', () => {
|
||||
expect(formatNumber(9999999.99, 'es-US', '1.2-2')).toEqual('9,999,999.99');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -6,14 +6,14 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import localeEn from '@angular/common/locales/en';
|
||||
import localeEnAU from '@angular/common/locales/en-AU';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import localeHe from '@angular/common/locales/he';
|
||||
import localeZh from '@angular/common/locales/zh';
|
||||
import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
|
||||
import localeEn from '@angular/common/locales/en';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import localeZh from '@angular/common/locales/zh';
|
||||
import localeEnAU from '@angular/common/locales/en-AU';
|
||||
import localeHe from '@angular/common/locales/he';
|
||||
import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrencyDigits, getLocaleDirection} from '../../src/i18n/locale_data_api';
|
||||
import {FormatWidth, getCurrencySymbol, getLocaleDateFormat, getLocaleDirection, getNumberOfCurrencyDigits} from '../../src/i18n/locale_data_api';
|
||||
|
||||
{
|
||||
describe('locale data api', () => {
|
||||
@ -25,7 +25,9 @@ import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrency
|
||||
ɵregisterLocaleData(localeHe);
|
||||
});
|
||||
|
||||
afterAll(() => { ɵunregisterLocaleData(); });
|
||||
afterAll(() => {
|
||||
ɵunregisterLocaleData();
|
||||
});
|
||||
|
||||
describe('getting currency symbol', () => {
|
||||
it('should return the correct symbol', () => {
|
||||
@ -55,16 +57,19 @@ import {getCurrencySymbol, getLocaleDateFormat, FormatWidth, getNumberOfCurrency
|
||||
});
|
||||
|
||||
describe('getLastDefinedValue', () => {
|
||||
it('should find the last defined date format when format not defined',
|
||||
() => { expect(getLocaleDateFormat('zh', FormatWidth.Long)).toEqual('y年M月d日'); });
|
||||
it('should find the last defined date format when format not defined', () => {
|
||||
expect(getLocaleDateFormat('zh', FormatWidth.Long)).toEqual('y年M月d日');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDirectionality', () => {
|
||||
it('should have correct direction for rtl languages',
|
||||
() => { expect(getLocaleDirection('he')).toEqual('rtl'); });
|
||||
it('should have correct direction for rtl languages', () => {
|
||||
expect(getLocaleDirection('he')).toEqual('rtl');
|
||||
});
|
||||
|
||||
it('should have correct direction for ltr languages',
|
||||
() => { expect(getLocaleDirection('en')).toEqual('ltr'); });
|
||||
it('should have correct direction for ltr languages', () => {
|
||||
expect(getLocaleDirection('en')).toEqual('ltr');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import localeRo from '@angular/common/locales/ro';
|
||||
import localeSr from '@angular/common/locales/sr';
|
||||
import localeZgh from '@angular/common/locales/zgh';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import {LOCALE_ID, ɵunregisterLocaleData, ɵregisterLocaleData} from '@angular/core';
|
||||
import {TestBed, inject} from '@angular/core/testing';
|
||||
import {NgLocaleLocalization, NgLocalization, getPluralCategory} from '@angular/common/src/i18n/localization';
|
||||
import {getPluralCategory, NgLocaleLocalization, NgLocalization} from '@angular/common/src/i18n/localization';
|
||||
import {LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
{
|
||||
describe('l10n', () => {
|
||||
|
Reference in New Issue
Block a user