Riot.js 快速的JavaScript單元測(cè)試框架
更新時(shí)間:2009年11月09日 19:11:10 作者:
Riot是一個(gè)快速,富有表現(xiàn)力,上下文驅(qū)動(dòng) 的單元測(cè)試框架。最初是用于Ruby的單元測(cè)試,最近作者Alex Young又實(shí)現(xiàn)了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');
});
});
示例:
Ruby代碼
復(fù)制代碼 代碼如下:
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代碼
復(fù)制代碼 代碼如下:
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');
});
});
相關(guān)文章
最簡(jiǎn)單的javascript對(duì)象實(shí)例代碼
非常簡(jiǎn)單的js面向?qū)ο髮?shí)例代碼,主要是利用了this,對(duì)于js面向?qū)ο蟮膶W(xué)習(xí)資料,可以查看腳本之家以前的文章。2009-12-12javascript中的對(duì)象創(chuàng)建 實(shí)例附注釋
為了讓你的js代碼更加的專業(yè)與代碼的條理性,很多情況下都是定義成對(duì)象的方式來(lái)書寫代碼,想深入的朋友可以參考下。2011-02-02JavaScript 面向?qū)ο缶幊蹋?) 基礎(chǔ)
自從有了Ajax這個(gè)概念,JavaScript作為Ajax的利器,其作用一路飆升。JavaScript最基本的使用,以及語(yǔ)法、瀏覽器對(duì)象等等東東在這里就不累贅了。把主要篇幅放在如何實(shí)現(xiàn)JavaScript的面向?qū)ο缶幊谭矫妗?/div> 2010-05-05JavaScript 三種創(chuàng)建對(duì)象的方法
JavaScript中對(duì)象的創(chuàng)建有以下幾種方式 使用內(nèi)置對(duì)象 使用JSON符號(hào) 自定義對(duì)象構(gòu)造。大家可以參考下。2009-10-10JavaScript類和繼承 this屬性使用說(shuō)明
本文介紹了JavaScript里面的this屬性。這個(gè)屬性是理解JavaScript類和繼承的重要基礎(chǔ)。2010-09-09JavaScript面向?qū)ο笤O(shè)計(jì)二 構(gòu)造函數(shù)模式
在Javascript面向?qū)ο笤O(shè)計(jì)一——工廠模式 中介紹了使用CreateEmployee()函數(shù)創(chuàng)建員工類。ECMAScript中的構(gòu)造函數(shù)可以用來(lái)創(chuàng)建特定類型的對(duì)象,如Object和Array這樣的原生構(gòu)造函數(shù),在運(yùn)行時(shí)會(huì)自動(dòng)出現(xiàn)在執(zhí)行環(huán)境中,此外也可以創(chuàng)建自定義的構(gòu)造函數(shù),從而創(chuàng)建自定義對(duì)象類型的屬性和方法2011-12-12mapper--圖片熱點(diǎn)區(qū)域高亮組件官方站點(diǎn)
2007-12-12最新評(píng)論