[英]How to unittest async ngIf in Angular with karma
I have this code in my HTML file: 我的HTML文件中包含以下代码:
<ul *ngIf="results | async as dataResult">
<ng-container *ngFor="let result of dataResult">
<li class="global-search" *ngIf="result.results.length > 0">
<div class="wrapper">{{result.title.toUpperCase() | translate}}</div>
<ul *ngIf="result.results?.length > 0">
<li (click)="clickResult(row); isResultsOpen = false" class="list__item" *ngFor="let row of result.results">
{{row.location.name}}
</li>
</ul>
</li>
</ng-container>
</ul>
</div>
In my karma test, I want to check if the ngIf / ngFor
works and check the CSS classes. 在我的业力测试中,我想检查
ngIf / ngFor
有效,并检查CSS类。 How can I test this? 我该如何测试?
i try this in my test 我在测试中尝试
const searchService = jasmine.createSpyObj('SearchService', ['getResults']);
const results = searchService.getResults.and.returnValue(of(resultData));
it('show search results', fakeAsync(() => {
results.and.returnValue(resultData);
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(Boolean(fixture.debugElement.query(By.css('.global-search')))).toBeTruthy();
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.