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的更多相关文章

  1. [Angular + Unit Testing] Mock HTTP Requests made with Angular’s HttpClient in Unit Tests

    In a proper unit test we want to isolate external dependencies as much as possible to guarantee a re ...

  2. [Angular Unit Testing] Shallow Pipe Testing

    import { TestBed, ComponentFixture } from '@angular/core/testing'; import { BrowserDynamicTestingMod ...

  3. [Angular & Unit Testing] Testing a RouterOutlet component

    The way to test router componet needs a little bit setup, first we need to create a "router-stu ...

  4. [Angular & Unit Testing] Automatic change detection

    When you testing Component rendering, you often needs to call: fixture.detectChanges(); For example: ...

  5. [Angular & Unit Testing] Testing Component with Store

    When using Ngrx, we need to know how to test the component which has Router injected. Component: imp ...

  6. [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 ...

  7. [Angular Unit Testing] Testing Component methods

    import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...

  8. [Angular Unit Testing] Testing Services with dependencies

    import { Http, Response, ResponseOptions } from '@angular/http'; import { TestBed } from '@angular/c ...

  9. [Angular + Unit] AngularJS Unit testing using Karma

    http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma- ...

随机推荐

  1. php课程 12-38 php的类的构造方法和析构方法怎么写

    php课程 12-38 php的类的构造方法和析构方法怎么写 一.总结 一句话总结:a.__construct(参数){},__destruct(){},b.如果类中的一个方法和类名相同,则该方法为构 ...

  2. PHP中字符串比较的常用方法

    PHP中字符串比较的常用方法 一.总结 1.其实应该是直接等于号就可以了的 2.也可用strcmp,注意返回值 二.PHP中字符串比较的常用方法 1.按字节比较 按字节比较字符串是最常用的方法.其中可 ...

  3. iPad之Linux平台实践

    updata.... 本文出自 "李晨光原创技术博客" 博客,谢绝转载!

  4. ByteUtils

    package sort.bing.com; import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import j ...

  5. 洛谷 P2692 覆盖

    P2692 覆盖 题目背景 WSR的学校有B个男生和G个女生都来到一个巨大的操场上扫地. 题目描述 操场可以看成是N 行M 列的方格矩阵,如下图(1)是一个4 行5 列的方格矩阵.每个男生负责打扫一些 ...

  6. ubuntu下useradd与adduser差别,新建用户不再home文件夹下

    useradd username不会在/home下建立一个目录username adduser username会在/home下建立一个目录username useradd -m username跟a ...

  7. openstack之虚拟机创建流程分析

    这篇博文静静的呆在草稿箱大半年了.假设不是由于某些原因被问到,以及由于忽略它而导致的损失,否则我也不知道什么时候会将它完毕.感谢这段时间经历的挫折,让我知道不足.希望你能给我更大的决心! 本文试图具体 ...

  8. percona-toolkit的安装及简单介绍

    MySQL数据库是轻量级.开源数据库的佼佼者.其功能和管理,健壮性与Oracle相比还是有相当的差距.因此有非常多功能强大第三方的衍生产品,如percona-toolkit,XtraBackup等等. ...

  9. spring与cxf整合配置webservice接口(以jaxws:server的方式配置)

    ps:最近项目需要跟其他系统做同步,需要使用webservice来提供接口给其他系统调用:临时抱佛脚赶紧去网上找了下资料,发现用Endpoint的方式发布接口好容易哦:赶紧写了个例子做验证,发布成功. ...

  10. Altium Designer中原理图和pcb交叉查找

    转自:https://wenku.baidu.com/view/53ca06badbef5ef7ba0d4a7302768e9951e76e33.html 再看看:::: 转自:http://blog ...