Angular Тестирование кармы с помощью переменной Parent-to-Grandchild с использованием компонент extends - PullRequest
0 голосов
/ 18 февраля 2020

В тестировании Кармы у меня возникают проблемы с чтением значения переменной, когда переменная существует в компоненте «прародитель». Я попытался упростить приведенный ниже пример.
Переменная isLoading определена в Grandparent.component и используется в Grandchild.component. Переменная всегда преобразуется в «false» в Grandchild.component и будет корректно разрешаться в Parent.component. У кого-нибудь есть мысли о том, как заставить это работать с отношениями родитель-внук?

Пример:

Grandparent.component.ts

export abstract class GrandparentComponent {...
   public isLoading$: Observable<boolean>;
   this.isLoading$ = this.store.pipe(select(fromStore.isLoading)), 
}

Parent.component.ts

export abstract class ParentComponent extends SmartComponent implements OnInit {...}

Grandchild.component.ts

export class GrandchildComponent extends ParentComponent {...}

GrandchildComponent. html

<button id="myButton"
   (click)="someAction()"
   [disabled]="(isLoading$ | async)"
   <mat-icon svgIcon="edit"></mat-icon>
</button>

Grandchild.component.spe c .ts

it('should disable myButton when  isLoading', () => {
   component.isLoading$ = of(true);
   fixture.detectChanges();
   expect(instance.querySelector('#myButton').disabled).toBeTruthy();
});
...