zoukankan      html  css  js  c++  java
  • [Angular Unit Testing] Shallow Pipe Testing

    import { TestBed, ComponentFixture } from '@angular/core/testing';
    import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
    import { FileSizePipe } from './file-size.pipe';
    import {Component} from '@angular/core';
    
    TestBed.initTestEnvironment(
      BrowserDynamicTestingModule,
      platformBrowserDynamicTesting()
    );
    
    
    describe('FileSizePipe', () => {
    
    
      describe('Shallow Pipe Testing', () => {
        @Component({
          template: `size: {{size | filesize:suffix}}`
        })
        class TestComponent {
          suffix;
          size = 123456789;
        }
    
        let component : TestComponent;
        let fixture : ComponentFixture<TestComponent>;
        let el: HTMLElement;
    
        beforeEach(() => {
          TestBed.configureTestingModule({
            declarations: [
              FileSizePipe,
              TestComponent
            ]
          });
          fixture = TestBed.createComponent(TestComponent);
          component = fixture.componentInstance;
          el = fixture.nativeElement;
          fixture.detectChanges();
        });
    
        it('should convert bytes to megabytes', () => {
          expect(el.textContent).toContain('size: 117.74MB');
          component.size = 1029281;
          fixture.detectChanges();
          expect(el.textContent).toContain('size: 0.98MB');
        });
    
        it('should use the default extension when not supplied', () => {
          component.suffix = 'myExt';
          fixture.detectChanges();
          expect(el.textContent).toContain('size: 117.74myExt');
        });
      });
    });
  • 相关阅读:
    实现自动更新文件
    IP零碎知识总结
    有关数据库操作的一些函数
    AppConfig有关零碎知识
    将文件上传到数据库 和 从数据库下载文件到本地
    如何学习编程
    像素、英寸、厘米之间的换算关系
    局域网
    JSP基础知识
    Exchange a,b without using other variables
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6790667.html
Copyright © 2011-2022 走看看