Testing standalone pipes with ngneat spectator?

Discussão em 'Angular' iniciado por Ghervis, Outubro 14, 2024.

  1. Ghervis

    Ghervis Guest

    My ngneat test used to work, but after I turned my pipe into standalone, it stopped working and gave me this error:

    Error: Unexpected "TimeAgoPipe" found in the "declarations"
    array of the "DynamicTestModule" NgModule, "TimeAgoPipe" is
    marked as standalone and can't be declared in any NgModule -
    did you intend to import it instead (by adding it to the
    "imports" array)?


    Here's the snippet of my code that I changed:

    @Pipe({
    name: 'timeAgo',
    standalone: true // ADDED THIS.
    })
    export class TimeAgoPipe implements PipeTransform {
    // some implementation...
    }


    my spec:

    describe('TimeAgoPipe', () => {
    let spectator: SpectatorPipe<TimeAgoPipe>;

    const createPipe = createPipeFactory({
    pipe: TimeAgoPipe,
    providers: [
    // providers
    ],
    });

    // other tests..
    }


    I've been checking out the ngneat docs, there's nothing about standalone pipes. createComponentFactory has declareComponent:false to fix a similar issue, but what is the equivalent for pipes? How do i fix this?

    Continue reading...

Compartilhe esta Página