- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我对处理区域设置格式的非常具体的数字组件进行了多次测试。 Karma 的测试没问题,但是一旦我们将其更改为 Jest,这个错误就开始出现:
NoLocale:缺少“de-DE”的语言环境信息解决方案:http://www.telerik.com/kendo-angular-ui/components/internationalization/troubleshooting/#toc-no-locale
我尝试了所附链接中的所有建议,但没有一个成功。
IntlService
是用 en-US
locale id 初始化的,所以我为每个测试更改了它,具体取决于我想要断言的格式(de- DE
或 en-GB
).
这些是 component.spec.ts 中的测试示例:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NumericTextBoxComponent } from './numeric-textbox.component';
import { FormsModule } from '@angular/forms';
import { CldrIntlService, IntlModule, load } from '@progress/kendo-angular-intl';
describe('NumericTextBoxComponent', () => {
let component: NumericTextBoxComponent;
let fixture: ComponentFixture<NumericTextBoxComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ FormsModule, IntlModule ],
declarations: [ NumericTextBoxComponent ],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NumericTextBoxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('User writes valid numbers with German/International notation', () => {
component.format = 'n2';
(<CldrIntlService>component.intlService).localeId = 'de-DE';
fixture.detectChanges();
const displayValueInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('input');
// absolute integer
displayValueInput.value = '123456789';
displayValueInput.dispatchEvent(new Event('input'));
displayValueInput.dispatchEvent(new Event('focusout'));
expect(component.inputValue).toBe('123456789');
expect(component.displayValue).toBe('123.456.789,00');
});
it('displays the correct format when the control is created in english context', () => {
component.format = 'n2';
(<CldrIntlService>component.intlService).localeId = 'en-GB';
fixture.detectChanges();
const displayValueInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('input');
displayValueInput.value = '123456789.12';
displayValueInput.dispatchEvent(new Event('input'));
displayValueInput.dispatchEvent(new Event('focusout'));
expect(component.inputValue).toBe('123456789.12');
expect(component.displayValue).toBe('123,456,789.12');
});
很少见的是“en-GB”语言环境被 Intl Service 识别(因此测试运行良好),但“de-DE”则不然。
我的问题是:如何将de-DE
locale信息导入测试环境,让Intl Service动态识别?
fixture.whenStable().then(()=> {})
导致测试错误处理出现问题,因此已将其删除。
作为附加信息,focusout
事件在组件中触发以下方法:
onFocusOut(first: boolean = false): void {
console.log("onFocusOut");
if (this.isReadOnly && !first && !this.isFocusIn) { return; }
this.isFocusIn = false;
// save the temporal the editable display value into the inputValue.
// if the escape key was pressed, then we undo the actual displayValue to the lastInputValue.
this.inputValue = !this.wasEscapePressed ? this.displayValue : this.lastInputValue;
this.wasEscapePressed = false;
// update the readable display value with the absolute value of the input value (or zero if it is null, zero or empty).
this.displayValue = this.formatDisplayValue(this.inputValue);
}
formatDisplayValue(input: string): string {
// single signs, nulls, empty and zeros are shown as zero
if (this.checkNullZeroOrEmpty(input) || this.isSignOnly(input)) {
input = NumericTextBoxComponent.ZERO;
} else if (this.IsPositiveValue(input) && input[0] === NumericTextBoxComponent.PLUS_SIGN) {
// positive signs at the beginning are trim
input = input.replace(NumericTextBoxComponent.PLUS_SIGN, '');
}
// display value are always the absolute value
const numberValue = Math.abs(this.getNumberValue(input));
// finally return the number formatted based in the locale.
return this.intlService.formatNumber(numberValue, this.format);
}
因此,当我将焦点移出输入 HTML 元素时,显示值的格式取决于语言环境。
最佳答案
我建议您尝试按照您在章节 loading additional locale data 中链接到的文档中的描述导入它.由于您没有提到加载其他语言环境,我假设您根本没有这样做。否则,请提供您如何加载它们的其他信息。
对于 de locale,您需要添加以下导入。
// Load all required data for the de locale
import '@progress/kendo-angular-intl/locales/de/all';
关于angular - 在 Angular 7 中使用 Jest 进行测试时缺少 Kendo Intl Service 的语言环境信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56021722/
我正在尝试在 Kendo 网格中获取 Kendo Tree 。 我可以实现获取数据,但不能实现树功能。 下面是相同的链接 http://dojo.telerik.com/oDakE 任何人都可以帮助我
我使用的是 Kendo Treeview ,在 Kendo Treeview 节点中,我嵌入了 Kendo 下拉菜单。 一切正常,下拉列表出现在 Treeview 节点上,但是当我展开 treevie
我在同一页面上有 TreeView 和 Grid,我需要从网格数据填充 TreeView。所以流程是这样的: 用户从下拉列表中选择某项内容并单击按钮 -> Web 服务调用 -> 使用来自 Web 服
我正在尝试在 Treeview 中嵌套一个窗口。我想要这样,当用户选择一个特定的节点时,它会打开一个 Kendo 窗口。有没有人做过这个?我在演示中没有看到太多类似的东西。 我正在使用 mvc 包装器
我想知道是否可以加载 kendo.View(...) 或 kendo.layout(...) 的内容一个单独的 html 文件? 这是剑道的例子Hello World Single Page Appl
我有 Kendo HierarchicalDataSource绑定(bind)到 Kendo 的对象 treeview小部件。 HierarchicalDataSource只返回一个一级深度的 jso
我想为 kendo-grid-react-wrapper 引入类似 kendoDateRangePicker 的东西。有 kendoDatePicker 允许您只选择一个日期而不是两个: filter
我正在尝试将 Kendo UI MVVM 框架与 Kendo UI 拖放机制结合使用;但我很难找到如何将数据从 draggable 对象中删除。 我的代码是这样的...... var viewMode
我正在尝试最新的 Kendo UI Web 版本,以便在我们的应用程序中使用它,特别是网格组件。 如图here网格能够在移动设备或任何浏览器中进行自适应渲染,如果 mobile属性设置为“手机”或“平
Kendo UI Web 和 Kendo UI Core 之间有什么区别 https://www.nuget.org/packages/KendoUIWeb http://www.nuget.org/
我正在尝试将 Kendo UI MVVM 框架与 Kendo UI 拖放机制结合使用;但是我很难找到如何从 draggable 对象中删除数据。 我的代码是这样的…… var viewModel =
我正在尝试最新的 Kendo UI Web 版本,以便在我们的应用程序中使用它,特别是网格组件。 如图here网格能够在移动设备或任何浏览器中进行自适应渲染,如果 mobile属性设置为“手机”或“平
KendoUI 版本 2013.3.1119使用 Kendo MVVM 我有一个我构建的颜色选择器,它使用平面颜色选择器和使用调色板的颜色选择器。它们都可以正常运行,但平面颜色选择器的布局已关闭, s
我使用以下方法显示格式化为百分比的数值: columns.push( { field: key, hidden:
Hello 使用类似于此示例的复选框实现了自定义过滤器菜单: http://dojo.telerik.com/@SiliconSoul/oBoCu 我的问题是,如果用户选择/取消选择了一些复选框,但从
网格列可以调整大小。我想存储用户调整的列宽并在下一个 session 开始时恢复它们。 我发现存储列宽的最佳方法如下: var element = $('#grid').kendoGrid({
我有一个Kendo ui图表,该图表显示来自动态数据源的柱形图。但有时图表会打开可用空间大小的一半。当我单击某些链接或更改日期时,它会自动调整大小。知道为什么会导致它吗? 在数据源更改事件中,当它显示
我发现 kendoui 图表有两种方法:refresh方法和redraw方法,有什么区别?我想他们俩都是再画一次图表。但是如果图表是根据 ajax 从远程数据绑定(bind)的,则请求不会再次触发。
我有一个包含太多列的剑道网格。最初我选择隐藏一些列,但后来我决定用水平滚动条显示所有列。 我通过为每一列分配宽度来做到这一点。当我这样做时,每列之间的行与标题行不同步。 我的意思是,网格数据部分的行相
enter image description here 我正在尝试使用带有复选框的 Treeview 来定义用户权限。 (2 个 Action - 启用/禁用正确) 如何从父节点获取值(id)? K
我是一名优秀的程序员,十分优秀!