ngneat / spectator

🦊 🚀 A Powerful Tool to Simplify Your Angular Tests
https://ngneat.github.io/spectator
MIT License
2.08k stars 177 forks source link

createPipe doesn't pickup arguments to pipes #600

Open martin-juul opened 1 year ago

martin-juul commented 1 year ago

Is this a regression?

No

Description

When testing a pipe it is not possible to pass arguments to the pipe.

describe('FooPipe', () => {
  let spectator: SpectatorPipe<FooPipe>;
  const createPipe = createPipeFactory(FooPipe);

  it('should change the background color', () => {
    // @ts-ignore used in template
    const model = {a: 1, b: 2, c: 3};

    spectator = createPipe(`<div>{{ 'EUR 0' | fooPipe: model }}</div>`, {
      hostProps: model,
    });

    expect(spectator.element).toHaveText('foobar');
  });
});

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

TypeError: Cannot read property 'tender' of undefined
    at FooPipe.transform (projects/foo/src/app/foo.ts:13:15)
    at pureFunction2Internal (node_modules/@angular/core/fesm2015/core.mjs:22302:1)
    at ɵɵpipeBind2 (node_modules/@angular/core/fesm2015/core.mjs:22484:1)
    at HostComponent_Template (ng:///HostComponent.js:14:33)
    at executeTemplate (node_modules/@angular/core/fesm2015/core.mjs:9717:1)
    at refreshView (node_modules/@angular/core/fesm2015/core.mjs:9580:1)
    at refreshComponent (node_modules/@angular/core/fesm2015/core.mjs:10777:1)
    at refreshChildComponents (node_modules/@angular/core/fesm2015/core.mjs:9376:1)
    at refreshView (node_modules/@angular/core/fesm2015/core.mjs:9630:1)
    at renderComponentOrTemplate (node_modules/@angular/core/fesm2015/core.mjs:9697:1)

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

No

brampeirs commented 2 months ago

You have to specify host in your createPipeFactory. https://github.com/ngneat/spectator?tab=readme-ov-file#using-custom-host-component

martin-juul commented 2 months ago

This is by default HostComponent as can be seen in https://github.com/ngneat/spectator/blob/defdeddbca73df6ca7642cd28e197281bb5c2c05/projects/spectator/src/lib/spectator-pipe/options.ts#L20

brampeirs commented 2 months ago

my bad :D