当我尝试测试我的角度应用程序时,我无故收到此错误,以下为完全错误
TypeError: (0 , _slash(...).default) is not a function
at viewWrappedDebugError (../../../packages/core/src/view/errors.ts:28:11)
at callWithDebugContext (../../../packages/core/src/view/services.ts:638:11)
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (../../../packages/core/src/view/services.ts:346:10)
at ViewRef_.detectChanges (../../../packages/core/src/view/refs.ts:261:16)
at ComponentFixture._tick (../../../../packages/core/testing/src/component_fixture.ts:107:28)
at ../../../../packages/core/testing/src/component_fixture.ts:120:36
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:391:26)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../node_modules/zone.js/dist/proxy.js:129:39)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:390:52)
at Object.onInvoke (../../../packages/core/src/zone/ng_zone.ts:273:25)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:390:52)
at Zone.Object.<anonymous>.Zone.run (../../node_modules/zone.js/dist/zone.js:150:43)
at NgZone.run (../../../packages/core/src/zone/ng_zone.ts:171:50)
at ComponentFixture.detectChanges (../../../../packages/core/testing/src/component_fixture.ts:120:19)
at src/app/projects/project-create/project-create.component.spec.ts:129:13
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:391:26)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../node_modules/zone.js/dist/proxy.js:129:39)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:390:52)
at Zone.Object.<anonymous>.Zone.run (../../node_modules/zone.js/dist/zone.js:150:43)
at Object.testBody.length (../../node_modules/jest-preset-angular/zone-patch/index.js:52:27)
在我看来错误发生的那行看起来完全合法
fixture.detectChanges();
包含在我的beforeEach
区块中。
beforeEach(() => {
AppConfig.settings = JSONConfig;
fixture = TestBed.createComponent(ProjectCreateComponent);
component = fixture.componentInstance;
fixture.detectChanges();
el = fixture.nativeElement;
});
我似乎无法在整个堆栈溢出中找到解决此问题的方法,而且我很确定我不是唯一遇到此问题的人。感谢您的提前帮助!
编辑
我还发现,通常console.log
会导致此TypeError,并且我已经从组件中删除了所有控制台日志
答案 0 :(得分:0)
由于export const validateObjectId = (request: Request, response: Response, next: NextFunction) => {
Object.values(request.params).forEach((param) => {
if (!ObjectId.isValid(param)) {
errorConstants.sendErrorResponse(response, errorConstants.invalid_object_id);
}
});
next();
};
未正确初始化,因此出现错误。您可以共享ProjectCreateComponent
的初始化代码,以便可以查找问题。另外,在某些情况下,由于导入模块的方式不正确,也会发生此错误。
答案 1 :(得分:0)
四处张望后,我能够找到出现此错误的原因。我使用(ngModel)
跟踪用户输入,因此可以动态填充对话框。那是导致错误的原因。如果您遇到此错误,请注意以下几点。
console.logs
(ngModel)
,请从表单中删除formbuilder
,而不要使用类似this.yourForm.get('formControlName').value;
的消气剂如果遇到任何导致此荒谬错误的元凶,请随时添加!