Files
cocos4/test/qunit/unit/test-component.js
T
2016-04-08 17:27:01 +08:00

69 lines
2.1 KiB
JavaScript

largeModule('Component', SetupEngine);
test('Inheritance of editor properties', function () {
var base = cc.Class({
extends: cc.Component,
editor: {
inspector: 'jare.html',
icon: 'guo.png',
executeInEditMode: true,
playOnFocus: true,
}
});
var child = cc.Class({
extends: base
});
ok(!child._inspector, 'should not inherit inspector from base component');
ok(!child._icon, 'should not inherit icon from base component');
strictEqual(child._executeInEditMode, true, 'should inherit executeInEditMode from base component');
strictEqual(child._playOnFocus, true, 'should inherit playOnFocus from base component');
});
test('_isOnLoadCalled', function () {
var Comp = cc.Class({
extends: cc.Component,
onLoad: function () {
this.updateSprite();
},
updateSprite: function () {
equal(!!this._isOnLoadCalled, false, 'it should be false during onLoad');
},
});
var node = new cc.Node();
cc.director.getScene().addChild(node);
var comp = node.addComponent(Comp);
equal(!!comp._isOnLoadCalled, true, 'it should be true after onLoad');
});
test('should not cause an infinite loops if re-activated in onLoad', function () {
var Comp = cc.Class({
extends: cc.Component,
onLoad: function () {
this.node.active = false;
this.node.active = true;
}
});
var node = new cc.Node();
cc.director.getScene().addChild(node);
var comp = node.addComponent(Comp);
ok('done');
});
//test('should not call lifecycle methods if not executeInEditMode', function () {
// var Comp = cc.Class({
// extends: CallbackTester,
// ctor: function () {
// this.notExpect(CallbackTester.OnLoad, 'onLoad');
// this.notExpect(CallbackTester.OnEnable, 'onEnable');
// }
// });
//
// var parent = new cc.Node();
// cc.director.getScene().addChild(parent);
// var comp = parent.addComponent(Comp);
// comp.stopTest();
//});