我有一个像这样的测试
@Component(
selector: 'my-test',
template: 'none',
changeDetection: ChangeDetectionStrategy.OnPush,
)
class MyTestComponent {
final AngularClientCache clientCache;
MyTestComponent(this.clientCache) {
assert(clientCache != null);
}
}
@Component(
selector: 'test',
directives: const <dynamic>[MyTestComponent],
template: r'<my-test></my-test>',
)
class ComplexTestComponent {
@ViewChild(MyTestComponent) MyTestComponent testComponent;
}
@AngularEntrypoint()
void main() {
tearDown(() => disposeAnyRunningTest());
group('AngularClientCache', () {
test('should store and return value', () async {
final testBed =
new NgTestBed<ComplexTestComponent>().addProviders(<dynamic>[
provide(AngularClientCache, useValue: new AngularClientCache())
]);
final fixture = await testBed.create();
// Create an instance of the in-browser page loader that uses our fixture.
final loader = new HtmlPageLoader(
fixture.rootElement.parent,
executeSyncedFn: (c) async {
await c();
return fixture.update;
},
useShadowDom: false,
);
final complex =
await loader.getInstance<ComplexTestComponent>(ComplexTestComponent);
print(complex.testComponent); // <<<=== print `null`
});
});
}
如何获得对MyTestComponent
组件的引用。我希望@ViewChild()
这样做,但它没有。也欢迎任何其他方法。