mercredi 6 septembre 2017

get a handle on a component in my testbed

When testing a component, how can I get a handle on a component displayed in it's template ?

Suppose I import MyModule that exports ExportedComponent

MyComponent's spec looks like this

beforeEach(async(() => {

  TestBed.configureTestingModule({
    import: [MyModule]
  })
    .compileComponents();
}));

And in MyComponent's template I have

<exported-component></exported-component>

I would like to call a method on the instance of ExportedComponent that is used in theMyComponent instance of the testbed.

For that I would need to get a handle on the instance of ExportedComponent. Something I would normally do with ViewChild.

How can I achieve that in that in a test context ?

Aucun commentaire:

Enregistrer un commentaire