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

    import { Pipe, PipeTransform } from '@angular/core';
    
    @Pipe({
      name: 'filesize'
    })
    export class FileSizePipe implements PipeTransform {
      transform(size: number, extension: string = 'MB') {
        return (size / (1024 * 1024)).toFixed(2) + extension;
      }
    }
    import { FileSizePipe } from './file-size.pipe';
    
    describe('FileSizePipe', () => {
    
      describe('Isolate FileSizePipe test', () => {
        
        const pipe = new FileSizePipe();
    
        it('should convert bytes to megabytes', () => {
          expect(pipe.transform(123456789)).toBe('117.74MB');
          expect(pipe.transform(987654321)).toBe('941.90MB');
        });
    
        it('should use the default extension when not supplied', () => {
          expect(pipe.transform(123456789)).toBe('117.74MB');
          expect(pipe.transform(987654321)).toBe('941.90MB');
        });
    
        it('should override the extension when supplied', () => {
          expect(pipe.transform(123456789, 'myExt')).toBe('117.74myExt');
          expect(pipe.transform(987654321, 'anotherExt')).toBe('941.90anotherExt');
        });
      });
    
    });
  • 相关阅读:
    2016.7.31整机升级计划
    UVa 1588
    UVa1587
    Jzoj4714 公约数
    Jzoj4714 公约数
    Jzoj4713 A
    Jzoj4713 A
    Jzoj4711 Binary
    Jzoj4711 Binary
    Jzoj4710 Value
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6789642.html
Copyright © 2011-2022 走看看