【发布时间】:2021-06-23 11:20:34
【问题描述】:
我正在使用 Angular 10 和 Jest 开发一个应用程序来测试我的应用程序。我输入了区域设置 ID fr-FR,它运行良好,但在我运行它们时没有在测试中:
Error: Missing locale data for the locale "fr-FR".
我不知道在哪里或如何在测试中一劳永逸地设置语言环境。我进行了失败的测试: :
import {LOCALE_ID} from '@angular/core';
import localeFr from '@angular/common/locales/fr';
import {registerLocaleData} from '@angular/common';
registerLocaleData(localeFr, 'fr-Fr');
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{
provide: LOCALE_ID,
useValue: 'fr-FR'
}
]
})})
我在日期格式化程序中使用区域设置日期:
export default class DateFormatter {
private static readonly YYYY_MM_DD = 'yyyy-MM-dd';
public static readonly LOCALE_DATE: string = 'fr-FR';
static formatDateDayWithDashes(date: Date) {
return !!date ? formatDate(date, this.YYYY_MM_DD, this.LOCALE_DATE) : undefined;
}
}
你知道我可以在哪里为所有测试设置一次语言环境吗?
【问题讨论】:
标签: angular jestjs internationalization