This repository has been archived by the owner on Jan 5, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesse Stuart
committed
Feb 23, 2012
1 parent
27de1cd
commit f51c1cf
Showing
11 changed files
with
93 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module 'Event' | ||
setup: -> | ||
@event = new Event | ||
|
||
test "handles subscribtions", -> | ||
callback = -> | ||
@event.subscribe callback | ||
equal @event.subscribers.length, 1 | ||
|
||
test "calls subscribers when triggered", -> | ||
@callback_count = 0 | ||
callback = => @callback_count += 1 | ||
@event.subscribers = [callback, callback, callback] | ||
@event.trigger() | ||
equal @callback_count, 3 | ||
|
||
test "calls subscribers with all arguments passed to trigger", -> | ||
@callback_args_count = 0 | ||
callback = (args...)=> @callback_args_count = args.length | ||
@event.subscribers = [callback] | ||
@event.trigger(1,2,3) | ||
equal @callback_args_count, 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice; | ||
|
||
module('Event', { | ||
setup: function() { | ||
return this.event = new Event; | ||
} | ||
}); | ||
|
||
test("handles subscribtions", function() { | ||
var callback; | ||
callback = function() {}; | ||
this.event.subscribe(callback); | ||
return equal(this.event.subscribers.length, 1); | ||
}); | ||
|
||
test("calls subscribers when triggered", function() { | ||
var callback; | ||
this.callback_count = 0; | ||
callback = __bind(function() { | ||
return this.callback_count += 1; | ||
}, this); | ||
this.event.subscribers = [callback, callback, callback]; | ||
this.event.trigger(); | ||
return equal(this.callback_count, 3); | ||
}); | ||
|
||
test("calls subscribers with all arguments passed to trigger", function() { | ||
var callback; | ||
this.callback_args_count = 0; | ||
callback = __bind(function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
return this.callback_args_count = args.length; | ||
}, this); | ||
this.event.subscribers = [callback]; | ||
this.event.trigger(1, 2, 3); | ||
return equal(this.callback_args_count, 3); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters