Files
cocos4/tests/tween/tween.test.ts
T
qiuguohua 043c4dcc3c Fix tween.sequence not supporting single parameter (#16443)
* fix tween.sequence

* add sequence unit test

* Fix tween.sequence not supporting single parameter

* semicolon added

---------

Co-authored-by: zxx43 <zxx43@hotmail.com>
Co-authored-by: qiuguohua <guohua.qiu@cocos.com>
2023-11-01 11:03:18 +08:00

66 lines
2.3 KiB
TypeScript

import { Vec3, System } from "../../cocos/core";
import { tween, Tween, TweenSystem } from "../../cocos/tween";
import { Node, Scene } from "../../cocos/scene-graph";
import { Component } from "../../cocos/scene-graph/component";
import { game, director } from "../../cocos/game";
test('remove actions by tag', function () {
const scene = new Scene('test-tags');
const node = new Node();
scene.addChild(node);
const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);
director.runSceneImmediate(scene);
tween(node).tag(1).repeat(10, tween<Node>().by(3, { scale : new Vec3(1, 1, 1) })).start();;
tween(node).tag(1).repeat(10, tween<Node>().by(3, { position: new Vec3(10,10,0) })).start();
Tween.stopAllByTag(1);
expect(TweenSystem.instance.ActionManager.getActionByTag(1, node)).toBeNull();
});
test('destroySelf', function () {
const scene = new Scene('test-destroy');
const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);
director.runSceneImmediate(scene);
const node = new Node();
var comp = node.addComponent(Component);
const onDestroy = comp.onDestroy = jest.fn(() => {});
scene.addChild(node);
tween(node).destroySelf().start();
game.step();
expect(onDestroy).toBeCalledTimes(1);
director.unregisterSystem(sys);
});
test('sequence', function () {
const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);
const node = new Node();
const target = new Vec3(10, 20, 30);
const tweenact = tween(node).to(1, {position: target}, { easing: "bounceOut" });
tween(node).sequence(tweenact).start();
for (let i = 0; i < 100; ++i) {
game.step();
}
// @ts-expect-error access private property
const action = tweenact._actions[0] as TweenAction;
// @ts-expect-error access private property
const props = action._props;
for (const property in props) {
const prop = props[property];
expect(Vec3.equals(prop.current, target)).toBeTruthy();
}
director.unregisterSystem(sys);
});