Skip to main content

ngMocks.revealAll

Behavior of ngMocks.revealAll repeats ngMocks.reveal, but, instead of returning the first suitable element, ngMocks.revealAll will collect all suitable elements and return all of them.

In a template like:

<app-form>
<ng-container block="personal">
<input appInput="firstName">
<input appInput="lastName">
</ng-container>
<ng-container block="address">
<input appInput="street">
<input appInput="city">
<input appInput="country">
</ng-container>
</app-form>

we can get the form, blocks and their inputs like:

// roots
const formEl = ngMocks.reveal('app-form');
const personalEl = ngMocks.reveal(formEl, ['block', 'personal']);
const addressEl = ngMocks.reveal('app-form', ['block', 'address']);

// 2 elements
const personalEls = ngMocks.revealAll(personalEl, AppInputDirective);

// 3 elements
const addressEls = ngMocks.revealAll(addressEl, AppInputDirective);