Skip to content

Instantly share code, notes, and snippets.

@zonoise
Created December 17, 2011 19:51
Show Gist options
  • Save zonoise/1491189 to your computer and use it in GitHub Desktop.
Save zonoise/1491189 to your computer and use it in GitHub Desktop.
QUnit Test for "jQuery Mobileでのアプリケーション開発にBackbone.jsを導入しよう"
//Test for Backbone.js sample app
//http://lab.dwango.jp/articles/jquery-mobile-app-development/2-add-mvc-with-backbone.html
module("Friend");
test("initialize",function(){
expect(1);
var friend = new Friend();
ok(friend,"initialize ok");
});
test("has data attribute",function(){
expect(1);
var friend = new Friend();
ok(friend.get("date"),"data ok");
});
test("has name and data attribute",function(){
expect(2);
var friend = new Friend({name: "hage"});
ok(friend.get("date"),"data ok");
same(friend.get("name"),"hage","name ok");
});
module("Friends",{
setup:function(){
this.friend = new Friend();
this.friends = new Friends();
},
teardown: function(){
delete this.friend;
delete this.friends;
}
});
test("initialize",function(){
expect(1);
ok(this.friends);
});
test("add Friend",function(){
expect(2);
var friend = new Friend({name:"hage"});
this.friends.add(friend);
same(this.friends.length,1,"collection length");
equals(friend ,this.friends.models[0]);
});
module("FriendView");
test("initialize",function(){
var friendview = new FriendView();
ok(friendview);
ok(friendview.collection);
ok(friendview.collection instanceof Friends);
});
test("addFriend",function(){
var friendview = new FriendView();
equals(friendview.collection.length,0);
friendview.addFriend();
equals(friendview.collection.length,1);
ok(friendview.collection.models[0] instanceof Friend );
});
test("events",function(){
$('<div id="friends"><button>クリック</button> <ul></ul> </div>').appendTo('#qunit-fixture');
var friendview = new FriendView();
$("#friends button").trigger("click");
equals(friendview.collection.length,1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment