some more tests

This commit is contained in:
Joe Germuska
2010-10-02 15:58:26 -05:00
parent 6278661294
commit d66f2ed161
5 changed files with 24 additions and 14 deletions

View File

@@ -1,28 +1,21 @@
$(document).ready(function() {
module("Bindable");
module("Backbone bindable");
test("bind and trigger", function() {
var obj = { counter: 0 }
_.extend(obj,Backbone.Bindable);
obj.bind('foo',function() { obj.counter += 1; });
obj.trigger('foo');
equals(obj.counter,1,'counter should be incremented.');
});
test("repeated trigger", function() {
test("bindable: bind and trigger", function() {
var obj = { counter: 0 }
_.extend(obj,Backbone.Bindable);
obj.bind('foo',function() { obj.counter += 1; });
obj.trigger('foo');
equals(obj.counter,1,'counter should be incremented.');
obj.trigger('foo');
obj.trigger('foo');
obj.trigger('foo');
obj.trigger('foo');
equals(obj.counter,5,'counter should be incremented five times.');
});
test("bind, then unbind all functions", function() {
test("bindable: bind, then unbind all functions", function() {
var obj = { counter: 0 }
_.extend(obj,Backbone.Bindable);
var callback = function() { obj.counter += 1; }
@@ -32,8 +25,8 @@ $(document).ready(function() {
obj.trigger('foo');
equals(obj.counter,1,'counter should have only been incremented once.')
});
test("bind two callbacks, unbind only one", function() {
test("bindable: bind two callbacks, unbind only one", function() {
var obj = { counterA: 0, counterB: 0 }
_.extend(obj,Backbone.Bindable);
var callback = function() { obj.counterA += 1; };

0
test/collection.js Normal file
View File

14
test/model.js Normal file
View File

@@ -0,0 +1,14 @@
$(document).ready(function() {
module("Backbone model");
test("model: clone", function() {
attrs = { 'foo': 1, 'bar': 2, 'baz': 3};
a = new Backbone.Model(attrs);
b = a.clone();
equals(b.foo,a.foo,"Foo should be the same on the clone.");
equals(b.bar,a.bar,"Bar should be the same on the clone.");
equals(b.baz,a.baz,"Baz should be the same on the clone.");
});
});

View File

@@ -9,6 +9,9 @@
<script type="text/javascript" src="../backbone.js"></script>
<script type="text/javascript" src="bindable.js"></script>
<script type="text/javascript" src="model.js"></script>
<script type="text/javascript" src="collection.js"></script>
<script type="text/javascript" src="view.js"></script>
</head>
<body>
<h1 id="qunit-header">Backbone Test Suite</h1>

0
test/view.js Normal file
View File