Jasmine
2015-06-30 15:30
323 查看
describe(string,function) //suite测试集,可包含多个Specs(it),每个Specs(it)可包含多个expect
beforeAll,beforeEach,afterAll,afterEach //beforeAll:每个suite(即describe)中所有spec(即it)运行之前运行, beforeEach:每个spec(即it)运行之前运行
angular-mocks.js
inject
url:http://jasmine.github.io/2.0/introduction.html
https://docs.angularjs.org/api/ngMock
describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); }); });
beforeAll,beforeEach,afterAll,afterEach //beforeAll:每个suite(即describe)中所有spec(即it)运行之前运行, beforeEach:每个spec(即it)运行之前运行
(function(){ describe("Test 'this'", function() { beforeEach(function() { this.testCount = this.testCount || 0; this.testCount++; }); afterEach(function() { //this.testCount = 0; //无论是否有这行,结果是一样的,因为this指定的变量只能在每个spec的beforeEach/it/afterEach过程中传递 }); it("Spec 1", function() { expect(this.testCount).toBe(1); }); it("Spec 2", function() { expect(this.testCount).toBe(1); }); }); })();
angular-mocks.js
inject
angular.module('myApplicationModule', []) .value('mode', 'app') .value('version', 'v1.0.1'); describe('MyApp', function() { // You need to load modules that you want to test, // it loads only the "ng" module by default. beforeEach(module('myApplicationModule')); // inject() is used to inject arguments of all given functions it('should provide a version', inject(function(mode, version) { expect(version).toEqual('v1.0.1'); expect(mode).toEqual('app'); })); // The inject and module method can also be used inside of the it or beforeEach it('should override a version and test the new version is injected', function() { // module() takes functions or strings (module aliases) module(function($provide) { $provide.value('version', 'overridden'); // override version here }); inject(function(version) { expect(version).toEqual('overridden'); }); }); });
url:http://jasmine.github.io/2.0/introduction.html
https://docs.angularjs.org/api/ngMock
相关文章推荐
- C++程序的编写和实现
- 黑马程序员-OC语言-依赖关系(听课笔记)
- hibernate.cfg.xml报错原因之一
- Ubuntu 下的Android Studio如何设置主题
- 面向对象的特征
- kernel版本更新追踪
- 算法导论29(线性规划)
- 《数据结构与算法分析c++描述》读书笔记一——表
- 用C简单实现factorial(阶乘)算法
- M12以太网接口
- 截屏
- 修改UITabbaritems的字体大小和选中颜色
- Netty游戏服务器之六服务端登录消息处理
- iOS图片填充UIImageView(contentMode)
- Netty游戏服务器之六服务端登录消息处理
- hadoop2.x常用端口及定义方法
- JPG 批量压缩、 PNG32、PNG24转PNG 透明批量压缩工具 【JPNG】 支持多级目录
- 解决Cannot change version of project facet Dynamic web module to 2.5
- 使用 New Relic 监控接口服务性能
- Class com.googlecode.jsonplugin.JSONWriter can not access a member of class*