当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Riot.js 快速的JavaScript单元测试框架

Javascript
Javascript解决常见浏览器兼容问题的12种方法
用AJAX返回HTML片段中的JavaScript脚本
javascript splice数组简单操作
jQuery 数据缓存data(name, value)详解及实现
javascript下动态this与动态绑定实例代码
javascript forEach函数实现代码
javascript bind绑定函数代码
javascript当onmousedown、onmouseup、onclick同时应用于同一个标签节点Element
jQuery DOM操作小结与实例
Extjs学习笔记之一 初识Extjs之MessageBox
Extjs学习笔记之二 初识Extjs之Form
Extjs学习笔记之三 extjs form更多的表单项
Extjs学习笔记之四 工具栏和菜单
EXT中xtype的含义分析
Extjs学习笔记之五 一个小细节renderTo和applyTo的区别
jQuery DOM操作 基于命令改变页面
让多个输入框中的内容同时变化的js代码
判断iframe是否加载完成的完美方法
IE iframe的onload方法分析小结
javascript new一个对象的实质

Javascript 中的 Riot.js 快速的JavaScript单元测试框架


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 59 ::
收藏到网摘: n/a

Riot是一个快速,富有表现力,上下文驱动 的单元测试框架。最初是用于Ruby的单元测试,最近作者Alex Young又实现了Riot的JavaScript版- Riot.js。 http://github.com/alexyoung/riotjs
示例:
Ruby代码
复制代码 代码如下:

context "a new user" do
setup { User.new }
asserts("that it is not yet created") { topic.new_record? }
end
context "a new user" do
setup { User.new }
asserts("that it is not yet created") { topic.new_record? }
end

Javascript代码
复制代码 代码如下:

Riot.run(function() {
context('basic riot functionality', function() {
given('some simple equality tests', function() {
asserts('a simple truth test should return true', true).isTrue();
asserts('isNull is null', null).isNull();
});
given('another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});
given('a context concerned with functions', function() {
asserts('asserts() should allow functions to be compared', function() {
return 'test string';
}).equals('test string');
});
});
given('yet another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});
});