Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda