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

149
Views
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 answers
Answer question

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 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!