angular - Angular Unit Testing面临初始化表单和订阅表单值变化的问题
问题描述
我是角度单元测试的新手,实际上我在初始化表单组时遇到了问题
it('should be able to init forms', () => {
service.organizationForm = formBuilder.group({})
service.initOrganizationForm()
})
在此函数中调用 initOrganizationForm 函数时有 catch
this.organizationForm.valueChanges.
subscribe(form => {
this.organizationButtonsData[1]['disabled'] = this.organizationForm.valid ? false : true;
this.getRequiredCount();
});
所以因为这段代码我收到了这个错误
should be able to init forms
Setting Management Service
TypeError: Cannot read property 'valueChanges' of undefined
at <Jasmine>
at SettingManagementService.valueChanges [as initOrganizationForm] (http://localhost:9876/_karma_webpack_/src/app/core/services/settings.management.service.ts:465:31)
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/core/services/settings.management.service.spec.ts:74:17)
解决方案
推荐阅读
- c# - 如何创建 Visual Studio“添加引用”项来导入我的 C# COM 函数以及这些函数所依赖的 C++ DLL?
- php - 在其中一个字段值中使用 ENTER 接收 PHP 中的 JSON POST
- javascript - 意外的标记 ; 定义布尔变量时
- c++ - 基类中的成员函数包装器
- sql - Teradata - Where 子句中的案例语句?
- r - 通过R中其他两列的成对组合计算一列的唯一值
- python - Jupyter 笔记本幻灯片输出
- r - 我如何分组,总结然后选择最小值和最大值?
- java - 使用大纲文本字段的工具栏问题
- angular - 有没有一种方法可以显示带有角度材料形式的标签的静态文本,其样式类似于输入,以便它们共享排版?