测试 getLocaleFirstDayOfWeek
Testing getLocaleFirstDayOfWeek
瑞典周从星期一开始。使用 getLocaleFirstDayOfWeek
获取一周的第一天。测试时,它一直提供星期日作为一周的第一天。它需要测试来注册本地数据才能正常工作。这是缺陷还是符合预期?
import { getLocaleFirstDayOfWeek, registerLocaleData, WeekDay } from '@angular/common';
import EN_SE from '@angular/common/locales/en-SE';
describe('getLocaleFirstDayOfWeek', () => {
beforeAll(() => registerLocaleData(EN_SE, 'en-SE'));
fit('should start the week on monday', () => {
const firstDayOfWeek = getLocaleFirstDayOfWeek('en-SE');
expect(firstDayOfWeek).toEqual(WeekDay.Monday);
});
});
好的找到答案了!从 Angular 5 开始,默认情况下仅包含 en-US
,任何其他语言环境都需要通过 registerLocaleData
.
注册
By default Angular now only contains locale data for the language en-US, if you set the value of LOCALE_ID to another locale, you will have to import new locale data for this language because we don’t use the intl API anymore.
瑞典周从星期一开始。使用 getLocaleFirstDayOfWeek
获取一周的第一天。测试时,它一直提供星期日作为一周的第一天。它需要测试来注册本地数据才能正常工作。这是缺陷还是符合预期?
import { getLocaleFirstDayOfWeek, registerLocaleData, WeekDay } from '@angular/common';
import EN_SE from '@angular/common/locales/en-SE';
describe('getLocaleFirstDayOfWeek', () => {
beforeAll(() => registerLocaleData(EN_SE, 'en-SE'));
fit('should start the week on monday', () => {
const firstDayOfWeek = getLocaleFirstDayOfWeek('en-SE');
expect(firstDayOfWeek).toEqual(WeekDay.Monday);
});
});
好的找到答案了!从 Angular 5 开始,默认情况下仅包含 en-US
,任何其他语言环境都需要通过 registerLocaleData
.
By default Angular now only contains locale data for the language en-US, if you set the value of LOCALE_ID to another locale, you will have to import new locale data for this language because we don’t use the intl API anymore.