[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- ...
随机推荐
- node----ajax请求太大报错------解决方法
//----分析主体程序var bodyParser = require(‘body-parser‘); app.use(bodyParser.json({limit: ‘50mb‘})); app. ...
- 【习题 7-8 UVA-12107】Digit Puzzle
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 枚举最大层数.(也即改变的数字个数 然后枚举第一个改哪个数字,第二个改哪个数字.. 一定要注意字典序问题. 每次优先 ...
- Beginning iOS Programming
Beginning iOS Programming 2014年 published by Wrox
- php设置http请求头信息和响应头信息
php设置http请求头信息和响应头信息 设置请求服务器的头信息可以用fsockopen,curl组件,header函数只能用来设置客户端响应的头信息,不能设置服务器的头信息. 例子; 一.head ...
- docker网络访问
一 docker网络访问 描述: 在启动容器的时候,如果不指定对应的参数,在容器外部是无法通过网络来访问容器内的网络应用和服务的.当容器中运行一些网络应用,要让外部访问这些应用时,可以通过-P或者-p ...
- VUE笔记 - 插值表达式 v-on: / @ 事件绑定 定时器运用
<body> <!-- 2. 创建一个要控制的区域 --> <div id="app"> <input type="button ...
- 使用Maven构建eclipse项目 (以zorka为例)
第一步:下载和配置Maven 下载地址:http://maven.apache.org/download.cgi 下载第二项(binary zip)后解压,如图. 第二步:添加环境变量 MAVEN_H ...
- vuepress折腾记
由于格式比较乱,所以直接拿图片粘贴过来了,详情请看原文链接https://lewiscutey.github.io/blog/blog/vuepress-theme-toos.html
- C++ tab键实现自动补全输入功能
一.简介 由于项目中写了个测试的控制台程序,是每次读取一行,即通过getline()来实现的,所以每次必须输入全路径名称,才能实现运行. 大家都觉得麻烦,就写了个tab键自动选择补全的. 目前基本可实 ...
- 【MemSQL Start[c]UP 3.0 - Round 1 E】Desk Disorder
[链接]h在这里写链接 [题意] 有N个人. 2N个座位. 现在告诉你这N个人它们现在的座位.以及它们想去的座位. 每个人可以去它们想去的座位或者就站在原地不动. 新的座位和旧的座位,都不允许一个座位 ...