• [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');
        });
      });
    
    });
  • 相关阅读:
    括号序列的dp问题模型
    粉刷匠
    木棍加工
    物流运输
    最短路图
    DP基础(线性DP)总结
    离散化
    树链剖分
    NOIP2016 “西湖边超萌小松鼠” 模拟赛
    NOI导刊 2009 提高二
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6789642.html
Copyright © 2020-2023  润新知