Files
cocos4/tests/core/test-event-system.js
T
pandamicro 1380e46c34 Unittest (#4973)
* unit test for ts

* Fix ts-jest warnings

* Remove puppeteer for now

* fix physics define and jest config for windows

* Replace Node ref with INode ref

* Fix ci issue

* Fix

* tweak

* tweak

* Fix vscode launcher

* now physics framework export all physics component (#28)

* tweaks
2019-07-25 17:15:20 +08:00

53 lines
1.5 KiB
JavaScript

module('EventTarget');
test('once', function () {
var target = new cc.EventTarget();
var fireEvent = new cc.Event('fire');
var cb1 = new Callback();
// once
target.once('fire', cb1.enable());
target.dispatchEvent(fireEvent);
cb1.once('should be invoked if registered by once')
.disable('should only invoke once 1');
target.dispatchEvent(fireEvent);
// once + on
var cb2 = new Callback().enable();
target.once('fire', cb1.enable());
target.on('fire', cb2);
target.dispatchEvent(fireEvent);
cb1.once('should be invoked if registered by once and before other callback');
cb2.once('should still be invoked if previous event was removed');
cb1.disable('should only invoke once 2');
target.dispatchEvent(fireEvent);
cb2.once('should not remove common event');
// on + once
target.once('fire', cb1.enable());
target.dispatchEvent(fireEvent);
cb2.once();
cb1.once('should be invoked if registered by once and after other callback')
.disable('should only invoke once 3');
target.dispatchEvent(fireEvent);
cb2.once();
});
test('call "once" twice', function () {
var target = new cc.EventTarget();
var cb1 = new Callback().enable();
var ctx = {};
target.once('fire', cb1, ctx, true);
target.once('fire', cb1, ctx, true);
target.emit('fire');
cb1.once('should be invoked only once')
.disable('should only invoke once');
target.emit('fire');
});