Angular 19 with ng-mocks: How can I configure mocked pipes as non-standalone?

Discussão em 'Angular' iniciado por Hakiim Rosli, Fevereiro 26, 2025.

  1. Hakiim Rosli

    Hakiim Rosli Guest

    I'm in the process of upgrading our Angular application from version 18 to 19. Angular 19 now marks all components, directives, and pipes as standalone by default. Since we’re not ready to migrate our entire codebase to the new standalone paradigm, we're using non-standalone components in our tests.

    However, when I run the tests, I encounter the following error:

    Error: Unexpected "MockOfTranslatePipe" found in the "declarations" array of the "MockOfTranslateModule" NgModule, "MockOfTranslatePipe" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead?



    In my tests, I mock the TranslatePipe from @ngx-translate/core using ng-mocks. I configured the global default in our test file as follows:

    ngMocks.config({
    defaultStandalone: false,
    });



    However, when I run the tests, I still encounter the following error:

    Error: Unexpected "MockOfTranslatePipe" found in the "declarations" array of the "MockOfTranslateModule" NgModule, "MockOfTranslatePipe" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead?



    My questions are:

    • Is there a supported way in ng-mocks to override the standalone flag on a per-mock basis (or globally) for Angular 19 so that my mocked pipes are treated as non-standalone?
    • If not, is the recommended workaround to create a custom dummy pipe that is explicitly non-standalone?

    Any help or guidance on how to proceed with this migration would be greatly appreciated!

    Continue reading...

Compartilhe esta Página