好像你正在尋找:
new DirectiveResolver().resolve(TestComponent) as Component).changeDetection
全碼:
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
'進口{} PipeResolver從 '@角/編譯器';'? – yurzui