我对在 Angular2+ 中进行测试比较陌生,并且正在设置我的文件进行测试。自从构建项目以来,我已经编写了很多代码,现在正在尝试测试其中的一部分。然而,许多这些测试现在都被破坏了,所以我现在试图删除不需要的默认测试或修复有用的测试。
这个特定的测试不会运行,因为它在遇到 It() 测试方法之前就失败了。我不确定我错过了什么,任何帮助将不胜感激。
我收到此错误:
Failed: Cannot read property 'subscribe' of undefined
TypeError: Cannot read property 'subscribe' of undefined
at AppComponent../src/app/app.component.ts.AppComponent.setupLanguageTranslation (src/app/app.component.ts:48:26)
at AppComponent../src/app/app.component.ts.AppComponent.ngOnInit (src/app/app.component.ts:32:14)
at checkAndUpdateDirectiveInline (node_modules/@angular/core/fesm5/core.js:22089:1)
at checkAndUpdateNodeInline (node_modules/@angular/core/fesm5/core.js:23353:1)
at checkAndUpdateNode (node_modules/@angular/core/fesm5/core.js:23315:1)
at debugCheckAndUpdateNode (node_modules/@angular/core/fesm5/core.js:23949:1)
at debugCheckDirectivesFn (node_modules/@angular/core/fesm5/core.js:23909:1)
at Object.eval [as updateDirectives] (ng:///DynamicTestModule/AppComponent_Host.ngfactory.js:9:9)
at Object.debugUpdateDirectives [as updateDirectives] (node_modules/@angular/core/fesm5/core.js:23901:1)
at checkAndUpdateView (node_modules/@angular/core/fesm5/core.js:23297:1)
Run Code Online (Sandbox Code Playgroud)
我尝试了各种具有类似问题的文章,包括但不限于:
App.component.ts
export class AppComponent implements OnInit, OnDestroy {
title = 'planox';
showError = false;
errorMessage = ''; …Run Code Online (Sandbox Code Playgroud)