"TypeError: Cannot read properties of undefined (reading 'pipe') error in Angular ng-mocks library unit test

41 views Asked by At

I am working on an Nx Angular project and I am trying to write a unit test using Jasmin Karma, but with the ng-mocks library. I am following some other examples I have in the project but it is still not working.

The error says "TypeError: Cannot read properties of undefined (reading 'pipe')"

Code of my unit test:

describe('DepartmentEditorComponent', () => {

  MockInstance.scope();

  beforeEach(() => MockBuilder([DepartmentEditorPerspectiveComponent,
        TranslateModule.forRoot(),
        NoopAnimationsModule,
        HttpClientModule,
        HttpClientTestingModule],
    [DepartmentPerspectiveModule,
                    AreasDataMaintenanceModule,
                    RouterModule.forRoot([]),
                    DepartmentDataService])
    .keep(CommonModule)
    .keep(FormBuilder)
    .keep(ReactiveFormsModule),
  );

  it('should create', () => {
    const fixture = MockRender(DepartmentEditorPerspectiveComponent);

    expect(fixture.point.componentInstance).toBeDefined();
  });
});

Code in my .ts file where error is happening:

ngOnInit(){
    this.subscriptions.push(this.router.events.pipe(filter(event => event instanceof NavigationEnd))
      .subscribe(() => this.setPageData()));

    this.setPageData()
    this.createButtons();

  }

Screenshot of error

I have tried adding modules that might be missing but the error persists. I assume that I am supposed to add the observable somehow to the test but I don't know how with the ng-mocks syntax. The same failed error happens

0

There are 0 answers