Riot.js 快速的JavaScript單元測試框架
更新時間:2009年11月09日 19:11:10 作者:
Riot是一個快速,富有表現(xiàn)力,上下文驅(qū)動 的單元測試框架。最初是用于Ruby的單元測試,最近作者Alex Young又實現(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)文章
javascript中的對象創(chuàng)建 實例附注釋
為了讓你的js代碼更加的專業(yè)與代碼的條理性,很多情況下都是定義成對象的方式來書寫代碼,想深入的朋友可以參考下。2011-02-02
JavaScript 面向?qū)ο缶幊蹋?) 基礎(chǔ)
自從有了Ajax這個概念,JavaScript作為Ajax的利器,其作用一路飆升。JavaScript最基本的使用,以及語法、瀏覽器對象等等東東在這里就不累贅了。把主要篇幅放在如何實現(xiàn)JavaScript的面向?qū)ο缶幊谭矫妗?/div> 2010-05-05
JavaScript面向?qū)ο笤O(shè)計二 構(gòu)造函數(shù)模式
在Javascript面向?qū)ο笤O(shè)計一——工廠模式 中介紹了使用CreateEmployee()函數(shù)創(chuàng)建員工類。ECMAScript中的構(gòu)造函數(shù)可以用來創(chuàng)建特定類型的對象,如Object和Array這樣的原生構(gòu)造函數(shù),在運(yùn)行時會自動出現(xiàn)在執(zhí)行環(huán)境中,此外也可以創(chuàng)建自定義的構(gòu)造函數(shù),從而創(chuàng)建自定義對象類型的屬性和方法2011-12-12最新評論

