zoukankan      html  css  js  c++  java
  • [Angular Unit Testing] Debug unit testing -- component rendering

    If sometime you want to log out the comonent html to see whether the html render correctly, you can do :

    import {TestBed, async, ComponentFixture} from '@angular/core/testing';
    import {AppComponent} from './app.component';
    import {AuFaInputComponent} from './lib/au-fa-input/au-fa-input.component';
    import {InputRefDirective} from './lib/common/input-ref.directive';
    import {DebugElement} from '@angular/core';
    import {By} from '@angular/platform-browser';
    
    describe('AppComponent', () => {
    
      let component: AppComponent,
        fixture: ComponentFixture<AppComponent>,
        el: DebugElement,
        emailField: DebugElement;
    
    
      beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [
            AppComponent, AuFaInputComponent, InputRefDirective
          ],
        }).compileComponents();
      }));
    
      beforeEach(() => {
    
        fixture = TestBed.createComponent(AppComponent);
        component = fixture.debugElement.componentInstance;
        el = fixture.debugElement;
        emailField = el.query(By.css('#email-field'));
    
        fixture.detectChanges();
      });
    
      it('should include the correct email icon inside the email input', async() => {
        // debug a component html
        console.log(emailField.nativeElement.outerHTML);
        expect(emaailField.query(By.css('i.icon.fa.fa-envelope'))).toBeTruthy();
      });
    });

    If you found that some tmeplate binding doesn't render, you might should add :

    fixture.detectChanges();

    to trigger change detection.

  • 相关阅读:
    ERRORCODE=4228, SQLSTATE=null
    DB2和Oracle中唯一约束和唯一索引对比
    SW 3D 样条曲线
    SW 快速操作
    spring依赖注入的方式(一)
    Oracle Connect By的用法
    转:min(x,y)高效算法
    【转】QQ盗号核心编程
    转:理解并解决GBK转UTF8奇数中文乱码
    Oracle数据库的导入和导出命令
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6994793.html
Copyright © 2011-2022 走看看