首页 > 其他 > 详细

[Angular Unit Testing] Testing Pipe

时间:2017-04-30 16:59:33      阅读:214      评论:0      收藏:0      [点我收藏+]
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‘);
    });
  });

});

 

[Angular Unit Testing] Testing Pipe

原文:http://www.cnblogs.com/Answer1215/p/6789642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!