Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Test component metadata

We just would like to test ChangeDetection value on few components but we don't find a way to access easly to component metadata. For pipe we have found:

it('should be marked as pure', () => {
        expect(new PipeResolver().resolve(TranslatePipe).pure).toEqual(true);
    });

Main problem here is to find a easy way to do it for component and check if it is OnPush or not. Any idea here? So thanks.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Seems you are looking for:

new DirectiveResolver().resolve(TestComponent) as Component).changeDetection

Full code:

import { Component, Pipe, ChangeDetectionStrategy } from '@angular/core';
import { PipeResolver, DirectiveResolver } from '@angular/compiler';

@Component({
  selector: 'app-banner',
  template: '<h1>{{title}}</h1>',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestComponent {
  title = 'Test Tour of Heroes';
}

@Pipe({
  name: 'translate',
  pure: true
})
export class TranslatePipe {
  transform() {

  }
}


describe('BannerComponent', () => {
  it('should be marked as pure', () => {
    expect(new PipeResolver().resolve(TranslatePipe).pure).toEqual(true);
  });

  it('should be marked as onPush', () => {
    expect((new DirectiveResolver().resolve(TestComponent) as Component).changeDetection).toEqual(ChangeDetectionStrategy.OnPush);
  });
});

Plunker Example

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda