So I get the Error: NG0302 when I execute npm run test, but I don´t use custom pipes

79 views Asked by At

So to put some context first my project is an Android app developed using Ionic 7, Angular and Capacitor.

I'm doing the unit tests by "npm run test" and at the moment just making sure there is no errors, so just adding some imports in the spec.ts for SQLite and RouterTestingModule for the most part.

There is just one error still remaining, one Error: NG0302 that with some research I figured out is an error that appears when you are using a custom pipe but not importing or declaring this pipe on your module or spec.ts in my case.

The thing is I´m not using ANY custom pipe, pretty sure I only use currency and date, the weirdest thing is that I use this pipes on multiple pages but only get this error in one of them, so I just don´t get what is wrong or how to fix it.

Could you help me?

Here is the entire error that appears to me:

Error: NG0302: The pipe 'date' could not be found in the 'VerCompraPage' component. Verify that it is declared or imported in this module. Find more at https://angular.io/errors/NG0302
error properties: Object({ code: -302 })
    at getPipeDef (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:22620:15)
    at ɵɵpipe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:22569:19)
    at templateFn (ng:///VerCompraPage.js:61:9)
    at executeTemplate (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:10971:17)
    at renderView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:12170:13)
    at renderComponent (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:12117:5)
    at renderChildComponents (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:12215:9)
    at renderView (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:12195:13)
    at ComponentFactory.create (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:13121:13)
    at initComponent (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/testing.mjs:26413:51)

(PD my main language is not english so sorry for weird written stuff in this.)

I´running my unit tests triying to fix de errors, but one remains and I don´t get why.

Here´s the code for the test, just the standard and basic one by:

import { ComponentFixture, TestBed } from'@angular/core/testing';
import { SQLite } from '@awesome-cordova-plugins/sqlite/ngx';


import { VerCompraPage } from './ver-compra.page';
import { RouterTestingModule } from "@angular/router/testing";

describe('VerCompraPage', () => {
  let component: VerCompraPage;
  let fixture: ComponentFixture<VerCompraPage>;

  beforeEach(async() => {
    await TestBed.configureTestingModule({
      providers: [SQLite],
      imports: [RouterTestingModule]
    }).compileComponents();
    fixture = TestBed.createComponent(VerCompraPage);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});
0

There are 0 answers