3

私は次のようなテストを持っています

@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()していましたが、そうではありません。他のアプローチも大歓迎です。

4

1 に答える 1