mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Tests: Clean up Emitter tests.
This commit is contained in:
parent
4c84c3dad5
commit
639bf07a47
1 changed files with 34 additions and 13 deletions
|
@ -16,15 +16,21 @@ test('on()', function() {
|
||||||
var emitter = new Item(),
|
var emitter = new Item(),
|
||||||
installed;
|
installed;
|
||||||
// fake event type registration
|
// fake event type registration
|
||||||
emitter._eventTypes = {mousemove: {install: function(){ installed = true;} } };
|
emitter._eventTypes = {
|
||||||
|
mousemove: {
|
||||||
|
install: function() {
|
||||||
|
installed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return !emitter.responds('mousemove');
|
return !emitter.responds('mousemove');
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
emitter.on('mousemove', function() {});
|
emitter.on('mousemove', function() {});
|
||||||
equals(function() {
|
equals(function() { return emitter.responds('mousemove'); }, true);
|
||||||
return emitter.responds('mousemove')
|
|
||||||
}, true);
|
|
||||||
equals(function() { return installed; }, true);
|
equals(function() { return installed; }, true);
|
||||||
|
|
||||||
// one time installation only
|
// one time installation only
|
||||||
installed = false;
|
installed = false;
|
||||||
emitter.on('mousemove', function() {});
|
emitter.on('mousemove', function() {});
|
||||||
|
@ -32,16 +38,27 @@ test('on()', function() {
|
||||||
|
|
||||||
emitter.on('customUnregistered', function() {});
|
emitter.on('customUnregistered', function() {});
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return emitter.responds('customUnregistered')
|
return emitter.responds('customUnregistered');
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('off()', function() {
|
test('off()', function() {
|
||||||
var emitter = new Item(),
|
var emitter = new Item(),
|
||||||
uninstalled, called = 0,
|
uninstalled,
|
||||||
handler = function () {called++},
|
called = 0,
|
||||||
handler2 = function () {};
|
handler = function () {
|
||||||
emitter._eventTypes = {mousemove: {uninstall: function(){ uninstalled = true;} } };
|
called++;
|
||||||
|
},
|
||||||
|
handler2 = function () {
|
||||||
|
};
|
||||||
|
|
||||||
|
emitter._eventTypes = {
|
||||||
|
mousemove: {
|
||||||
|
uninstall: function() {
|
||||||
|
uninstalled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
emitter.on('mousemove', handler);
|
emitter.on('mousemove', handler);
|
||||||
emitter.on('mousemove', handler2);
|
emitter.on('mousemove', handler2);
|
||||||
|
@ -52,12 +69,12 @@ test('off()', function() {
|
||||||
emitter.off('mousemove', handler2);
|
emitter.off('mousemove', handler2);
|
||||||
emitter.emit('mousemove');
|
emitter.emit('mousemove');
|
||||||
equals(function() { return called == 2; }, true);
|
equals(function() { return called == 2; }, true);
|
||||||
equals(function() { return !uninstalled }, true);
|
equals(function() { return !uninstalled; }, true);
|
||||||
|
|
||||||
emitter.off('mousemove', handler);
|
emitter.off('mousemove', handler);
|
||||||
emitter.emit('mousemove');
|
emitter.emit('mousemove');
|
||||||
equals(function() { return called == 2; }, true);
|
equals(function() { return called == 2; }, true);
|
||||||
equals(function() { return uninstalled }, true);
|
equals(function() { return uninstalled; }, true);
|
||||||
|
|
||||||
called = 0;
|
called = 0;
|
||||||
emitter.emit('custom');
|
emitter.emit('custom');
|
||||||
|
@ -70,9 +87,13 @@ test('off()', function() {
|
||||||
test('emit()', function() {
|
test('emit()', function() {
|
||||||
var emitter = new Item(),
|
var emitter = new Item(),
|
||||||
called,
|
called,
|
||||||
handler = function (e) {called = e};
|
handler = function (e) {
|
||||||
|
called = e;
|
||||||
|
};
|
||||||
// fake event type registration
|
// fake event type registration
|
||||||
emitter._eventTypes = {mousemove: {} };
|
emitter._eventTypes = {
|
||||||
|
mousemove: {}
|
||||||
|
};
|
||||||
emitter.on('mousemove', handler);
|
emitter.on('mousemove', handler);
|
||||||
emitter.on('custom', handler);
|
emitter.on('custom', handler);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue