Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipe issues in v13 #1587

Closed
satanTime opened this issue Jan 13, 2022 · 2 comments · Fixed by #1617
Closed

Pipe issues in v13 #1587

satanTime opened this issue Jan 13, 2022 · 2 comments · Fixed by #1617

Comments

@satanTime
Copy link
Member

Example pipe:

import { DatePipe } from '@angular/common';
import { Inject, Injectable, LOCALE_ID, Pipe, PipeTransform } from '@angular/core';

@Injectable()
@Pipe({
  name: 'tijdstip'
})
export class TijdstipPipe extends DatePipe implements PipeTransform {

  constructor(@Inject(LOCALE_ID) locale: string) {
    super(locale);
  }

  transform(value: null | undefined): null;
  transform(value: null | undefined, inclusiefSeconden: boolean): null;
  transform(value: Date | string | number | undefined): string | null;
  transform(value: Date | string | number | undefined, inclusiefSeconden: boolean): string | null;
  transform(value: Date | string | number | null | undefined): string | null
  transform(value: Date | string | number | null | undefined, inclusiefSeconden?: boolean): string | null {
    return super.transform(
      value,
      inclusiefSeconden ? 'dd/MM/yyyy HH:mm:ss' :'dd/MM/yyyy HH:mm',
      undefined,
      'nl-BE'
    );
  }

}

Example module:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { TijdstipPipe } from './tijdstip.pipe';
import { TimeagoCustomFormatter, TimeagoFormatter, TimeagoIntl, TimeagoModule } from 'ngx-timeago';

@NgModule({
  declarations: [
      TijdstipPipe,
      ....
      ],
     imports: [
       CommonModule,
       TimeagoModule.forChild({
       intl: {provide: TimeagoIntl, useClass: TimeAgoTranslation},
       formatter: { provide: TimeagoFormatter, useClass: TimeagoCustomFormatter }
     })],
     exports: [
         TijdstipPipe,
         ....,
         TimeagoModule
     ]
})
export class CorePipesModule {}

Testcase:

Fails with

Error: NG0302: The pipe 'tijdstip' could not be found in the 'AuditInfoComponent' component!. Find more at https://angular.io/errors/NG0302

when running a part in the test where it should trigger the Pipe.

The html for the component contains this: <span>{{info.date | tijdstip:true}}</span>

import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { CorePipesModule } from '@nx-workspace/pipes';
import 'html-validate/jest';
...
import { MockComponent, MockModule } from 'ng-mocks';

describe('AuditInfoComponent', () => {
  let component: AuditInfoComponent;
  let spectator: Spectator<AuditInfoComponent>

  const createComponent = createComponentFactory({
    component: AuditInfoComponent,
    imports: [
      MockModule(CorePipesModule)
    ]
  });

  beforeEach(() => {
    spectator = createComponent();
    component = spectator.component;
  });
  
   it('should create', () => {
    expect(component).toBeTruthy();
  });
  
  it('should contain valid html without user', () => {
      expect(spectator.element).toHTMLValidate();
    });
   ....
   

Originally posted by @SnakeSVx in #1427 (comment)

satanTime added a commit to satanTime/ng-mocks that referenced this issue Jan 17, 2022
@satanTime satanTime linked a pull request Jan 17, 2022 that will close this issue
satanTime added a commit that referenced this issue Jan 17, 2022
fix(core): parsing only own declarations #1587
@satanTime
Copy link
Member Author

v13.0.0-alpha.5 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

@satanTime
Copy link
Member Author

v13.0.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant