[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');
- });
- });
- });
[Angular Unit Testing] Testing Pipe的更多相关文章
- [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 ...
- [Angular Unit Testing] Shallow Pipe Testing
import { TestBed, ComponentFixture } from '@angular/core/testing'; import { BrowserDynamicTestingMod ...
- [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 ...
- [Angular & Unit Testing] Automatic change detection
When you testing Component rendering, you often needs to call: fixture.detectChanges(); For example: ...
- [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 ...
- [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 ...
- [Angular Unit Testing] Testing Component methods
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...
- [Angular Unit Testing] Testing Services with dependencies
import { Http, Response, ResponseOptions } from '@angular/http'; import { TestBed } from '@angular/c ...
- [Angular + Unit] AngularJS Unit testing using Karma
http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma- ...
随机推荐
- php数组时按值传递还是按地址传递
php数组时按值传递还是按地址传递 一.总结 1.数组都是按值:php普通变量和数组的赋值(=)是按值传递,对象的赋值(=)是按址传递 2.对象和按值和按址:对象的clone(用clone关键字)是按 ...
- GPU-Z:显卡体质、显卡各传感器实时状态的查看
1. TechPowerUp GPU-Z:查看显卡体质 下载地址:Download TechPowerUp GPU-Z | techPowerUp 点击 bus interface 后的?进行显卡的体 ...
- 72.挖掘CSDN密码到链表并统计密码出现次数生成密码库
list.h #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include & ...
- 洛谷P3273 [SCOI2011]棘手的操作
题目描述 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作:U x y: 加一条边,连接第x个节点和第y个节点A1 x v: 将第x个节点的权 ...
- 1.24 Python知识进阶 - 类与对象
类 语法格式: class Dog(object): print("the dog is barking ...") Dog为类名,object为要继承的基类,Dog类会从基类ob ...
- tooltip两个特殊的属性
<body style="margin: 50px;"> <!--两个特殊的属性--> <div id="selection"&g ...
- 【2017"百度之星"程序设计大赛 - 初赛(B)】Chess
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=776&pid=1001 [题意] 在这里写题意 [题 ...
- 洛谷 P2807 三角形计数
P2807 三角形计数 题目背景 三角形计数(triangle) 递推 题目描述 把大三角形的每条边n等分,将对应的等分点连接起来(连接线分别平行于三条边),这样一共会有多少三角形呢?编程来解决这个问 ...
- 关于JS的面向对象总结
什么是面向对象: 对象由两部分构成:属性 和 方法: 面向对象的特点: 1.封装:对于相同功能的代码,放在一个函数中,以后再用到此功能,只需要调用即可,无需再重写:避免大量冗余代码: 专业话说:低耦合 ...
- jQuery的原理
JQ的原理 jquery-1.xxx :专门为PC端诞生的类库,兼容所有的浏览器 jquery-2.xxx:当初是为了移动端而准备的,所以IE低版本浏览器一般不兼容,但是这个版本针对移动端的事件等操作 ...