mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-24 14:27:56 -05:00
linting test/bindable
This commit is contained in:
@@ -3,40 +3,40 @@ $(document).ready(function() {
|
||||
module("Backbone bindable");
|
||||
|
||||
test("bindable: bind and trigger", function() {
|
||||
var obj = { counter: 0 }
|
||||
var obj = { counter: 0 };
|
||||
_.extend(obj,Backbone.Bindable);
|
||||
obj.bind('foo',function() { obj.counter += 1; });
|
||||
obj.trigger('foo');
|
||||
obj.bind('event', function() { obj.counter += 1; });
|
||||
obj.trigger('event');
|
||||
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.');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
obj.trigger('event');
|
||||
equals(obj.counter, 5, 'counter should be incremented five times.');
|
||||
});
|
||||
|
||||
|
||||
test("bindable: bind, then unbind all functions", function() {
|
||||
var obj = { counter: 0 }
|
||||
var obj = { counter: 0 };
|
||||
_.extend(obj,Backbone.Bindable);
|
||||
var callback = function() { obj.counter += 1; }
|
||||
obj.bind('foo', callback);
|
||||
obj.trigger('foo');
|
||||
obj.unbind('foo');
|
||||
obj.trigger('foo');
|
||||
equals(obj.counter,1,'counter should have only been incremented once.')
|
||||
var callback = function() { obj.counter += 1; };
|
||||
obj.bind('event', callback);
|
||||
obj.trigger('event');
|
||||
obj.unbind('event');
|
||||
obj.trigger('event');
|
||||
equals(obj.counter, 1, 'counter should have only been incremented once.');
|
||||
});
|
||||
|
||||
test("bindable: bind two callbacks, unbind only one", function() {
|
||||
var obj = { counterA: 0, counterB: 0 }
|
||||
var obj = { counterA: 0, counterB: 0 };
|
||||
_.extend(obj,Backbone.Bindable);
|
||||
var callback = function() { obj.counterA += 1; };
|
||||
obj.bind('foo', callback);
|
||||
obj.bind('foo', function() { obj.counterB += 1 });
|
||||
obj.trigger('foo');
|
||||
obj.unbind('foo', callback);
|
||||
obj.trigger('foo');
|
||||
equals(obj.counterA,1,'counterA should have only been incremented once.')
|
||||
equals(obj.counterB,2,'counterB should have been incremented twice.')
|
||||
obj.bind('event', callback);
|
||||
obj.bind('event', function() { obj.counterB += 1; });
|
||||
obj.trigger('event');
|
||||
obj.unbind('event', callback);
|
||||
obj.trigger('event');
|
||||
equals(obj.counterA, 1, 'counterA should have only been incremented once.');
|
||||
equals(obj.counterB, 2, 'counterB should have been incremented twice.');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user