1. import { Pipe, PipeTransform } from '@angular/core';
  2.  
  3. @Pipe({
  4. name: 'filesize'
  5. })
  6. export class FileSizePipe implements PipeTransform {
  7. transform(size: number, extension: string = 'MB') {
  8. return (size / (1024 * 1024)).toFixed(2) + extension;
  9. }
  10. }
  1. import { FileSizePipe } from './file-size.pipe';
  2.  
  3. describe('FileSizePipe', () => {
  4.  
  5. describe('Isolate FileSizePipe test', () => {
  6.  
  7. const pipe = new FileSizePipe();
  8.  
  9. it('should convert bytes to megabytes', () => {
  10. expect(pipe.transform(123456789)).toBe('117.74MB');
  11. expect(pipe.transform(987654321)).toBe('941.90MB');
  12. });
  13.  
  14. it('should use the default extension when not supplied', () => {
  15. expect(pipe.transform(123456789)).toBe('117.74MB');
  16. expect(pipe.transform(987654321)).toBe('941.90MB');
  17. });
  18.  
  19. it('should override the extension when supplied', () => {
  20. expect(pipe.transform(123456789, 'myExt')).toBe('117.74myExt');
  21. expect(pipe.transform(987654321, 'anotherExt')).toBe('941.90anotherExt');
  22. });
  23. });
  24.  
  25. });

[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数组时按值传递还是按地址传递

    php数组时按值传递还是按地址传递 一.总结 1.数组都是按值:php普通变量和数组的赋值(=)是按值传递,对象的赋值(=)是按址传递 2.对象和按值和按址:对象的clone(用clone关键字)是按 ...

  2. GPU-Z:显卡体质、显卡各传感器实时状态的查看

    1. TechPowerUp GPU-Z:查看显卡体质 下载地址:Download TechPowerUp GPU-Z | techPowerUp 点击 bus interface 后的?进行显卡的体 ...

  3. 72.挖掘CSDN密码到链表并统计密码出现次数生成密码库

    list.h #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include & ...

  4. 洛谷P3273 [SCOI2011]棘手的操作

    题目描述 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作:U x y: 加一条边,连接第x个节点和第y个节点A1 x v: 将第x个节点的权 ...

  5. 1.24 Python知识进阶 - 类与对象

    类 语法格式: class Dog(object): print("the dog is barking ...") Dog为类名,object为要继承的基类,Dog类会从基类ob ...

  6. tooltip两个特殊的属性

    <body style="margin: 50px;"> <!--两个特殊的属性--> <div id="selection"&g ...

  7. 【2017"百度之星"程序设计大赛 - 初赛(B)】Chess

    [链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=776&pid=1001 [题意] 在这里写题意 [题 ...

  8. 洛谷 P2807 三角形计数

    P2807 三角形计数 题目背景 三角形计数(triangle) 递推 题目描述 把大三角形的每条边n等分,将对应的等分点连接起来(连接线分别平行于三条边),这样一共会有多少三角形呢?编程来解决这个问 ...

  9. 关于JS的面向对象总结

    什么是面向对象: 对象由两部分构成:属性 和 方法: 面向对象的特点: 1.封装:对于相同功能的代码,放在一个函数中,以后再用到此功能,只需要调用即可,无需再重写:避免大量冗余代码: 专业话说:低耦合 ...

  10. jQuery的原理

    JQ的原理 jquery-1.xxx :专门为PC端诞生的类库,兼容所有的浏览器 jquery-2.xxx:当初是为了移动端而准备的,所以IE低版本浏览器一般不兼容,但是这个版本针对移动端的事件等操作 ...