Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Metadatos del componente de prueba

Solo nos gustaría probar el valor de ChangeDetection en algunos componentes, pero no encontramos una forma de acceder fácilmente a los metadatos de los componentes. Para tubería hemos encontrado:

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

El problema principal aquí es encontrar una manera fácil de hacerlo para el componente y verificar si es OnPush o no. ¿Alguna idea aquí? Así que gracias.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Parece que estás buscando:

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

Código completo:

 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); }); });

Ejemplo de Plunker

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!