Search code examples
angularjasmineangular7

TypeError: (0 , _slash(...).default) is not a function


When I try to test my angular application I get this error for no obvious reason full error below

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)

The line where the error claims to be getting generated looks perfectly legal to me fixture.detectChanges(); contained in my beforeEach block.

beforeEach(() => {
    AppConfig.settings = JSONConfig;
    fixture = TestBed.createComponent(ProjectCreateComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
    el = fixture.nativeElement;
  });

I cannot seem to find a solution to this issue all over stack overflow and I am pretty sure I am not the only one encountering this. Thanks for your help in advance!

EDIT I also found out that often times console.log causes this TypeError and I have removed all console logs from the component


Solution

  • After looking far and wide I was able to find the reason I was getting this error. I was using an (ngModel) to track user input so I can dynamically populate a dialog box. That was causing the error. Here are a few things to look out for if you ever run into this error.

    • Remove or comment any console.logs in your spec file or your .ts file
    • Remove (ngModel) from your form if you're using a formbuilder instead use a getter like this this.yourForm.get('formControlName').value;

    Feel free to add to this if you ever come across any culprit that spits this absurd error!