Vitest for Angular

Discussão em 'Angular' iniciado por Park Jang, Março 31, 2025.

  1. Park Jang

    Park Jang Guest

    I am trying to use Vitest to write a unit test for an Angular project. I want to use testbed (@angular/core/testing) to configure the test module like below:

    beforeEach(async () => {
    await TestBed.configureTestingModule({
    imports: [TestComponent],
    providers: [
    ChangeDetectorRef,
    ElementRef,
    FormBuilder,
    { provide: Router, useValue: {} },
    ],
    }).compileComponents(); // Ensure external resources are resolved

    // Create the component instance
    const fixture = TestBed.createComponent(TestComponent);
    component = fixture.componentInstance;
    });


    I am trying to use testbed to use the use lifecycle hooks of Angular component. But with the code above, it throw the exception:

    Error: Component 'ChipComponent' is not resolved:
    templateUrl: ./chip.component.html
    Did you run and wait for 'resolveComponentResources()'?


    How can I fix this issue and use Vitest for Angular?

    Continue reading...

Compartilhe esta Página