Tone.js/test/core/Emitter.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-10-27 21:40:52 +00:00
define(["Test", "Tone/core/Emitter"], function (Test, Emitter) {
2015-08-18 20:32:08 +00:00
2015-10-27 21:40:52 +00:00
describe("Emitter", function(){
2015-08-18 20:32:08 +00:00
it ("can be created and disposed", function(){
2015-10-27 21:40:52 +00:00
var emitter = new Emitter();
2015-08-18 20:32:08 +00:00
emitter.dispose();
Test.wasDisposed(emitter);
});
it ("can bind events", function(done){
2015-10-27 21:40:52 +00:00
var emitter = new Emitter();
2015-08-18 20:32:08 +00:00
emitter.on("something", function(){
done();
emitter.dispose();
});
emitter.emit("something");
2015-08-18 20:32:08 +00:00
});
it ("can unbind events", function(){
2015-10-27 21:40:52 +00:00
var emitter = new Emitter();
2015-08-18 20:32:08 +00:00
var callback = function(){
throw new Error("should call this");
};
emitter.on("something", callback);
emitter.off("something", callback);
emitter.emit("something");
2015-08-18 20:32:08 +00:00
emitter.dispose();
});
2015-09-05 19:07:06 +00:00
it ("removes all events when no callback is given", function(){
2015-10-27 21:40:52 +00:00
var emitter = new Emitter();
2015-09-05 19:07:06 +00:00
emitter.on("something", function(){
throw new Error("should call this");
});
emitter.on("something", function(){
throw new Error("should call this");
});
emitter.off("something");
emitter.emit("something");
2015-09-05 19:07:06 +00:00
emitter.dispose();
});
2015-08-18 20:32:08 +00:00
it ("can pass arguments to the callback", function(done){
2015-10-27 21:40:52 +00:00
var emitter = new Emitter();
2015-08-18 20:32:08 +00:00
emitter.on("something", function(arg0, arg1){
expect(arg0).to.equal("A");
expect(arg1).to.equal("B");
emitter.dispose();
done();
});
emitter.emit("something", "A", "B");
2015-08-18 20:32:08 +00:00
});
it ("can mixin its methods to another object", function(done){
var emitter = {};
2015-10-27 21:40:52 +00:00
Emitter.mixin(emitter);
2015-08-18 20:32:08 +00:00
emitter.on("test", done);
emitter.emit("test");
2015-08-18 20:32:08 +00:00
});
});
});