Skip to main content

ngMocks.findInstances

Returns an array of all found components, directives, pipes or services which belong to the current element and all its children. If the element is not specified, then the current fixture is used.

  • ngMocks.findInstances( fixture?, directive )
  • ngMocks.findInstances( debugElement?, directive )

or simply with selectors which are supported by ngMocks.find.

  • ngMocks.findInstances( cssSelector?, directive )
const directives1 = ngMocks.findInstances(Directive1);const directives2 = ngMocks.findInstances(fixture, Directive2);const directives3 = ngMocks.findInstances(fixture.debugElement, Directive3);const pipes = ngMocks.findInstances(fixture.debugElement, MyPipe);const services = ngMocks.findInstance(fixture, MyService);
const directives1 = ngMocks.findInstances('div.node', Directive1);const directives2 = ngMocks.findInstances(['attr'], Directive2);const directives3 = ngMocks.findInstances(['attr', 'value'], Directive3);const pipes = ngMocks.findInstances('div span.text', MyPipe);
important

A css selector helps to find the first matched element. It will be used to look up the desired declaration.