Skip to content

Commit

Permalink
fix: fix animator's play & pause bug
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jun 8, 2019
1 parent 33dbc72 commit 84dd631
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class Animator
if (this.isEnded() && (currentTime === 0 || currentTime >= this.getActiveDuration())) {
this.setTime(-delay, true);
}
state[TICK_TIME] = this.getTime();

this.timerId = requestAnimationFrame((time: number) => {
state[PREV_TIME] = time;
Expand Down
29 changes: 29 additions & 0 deletions test/unit/Animator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as sinon from "sinon";
import Animator, { isDirectionReverse } from "../../src/Animator";
import { TICK_TIME } from "../../src/consts";

describe("Animator Test", () => {
describe("test Animator initialize", () => {
Expand Down Expand Up @@ -241,6 +242,33 @@ describe("Animator Test", () => {

animator.play();
});
it("should check play with (delay, playSpeed)", async () => {
const animator = new Animator({
delay: 2,
fillMode: "forwards",
direction: "normal",
duration: 5,
playSpeed: 1.5,
});

animator.setTime(2, true, true);
const tick1 = animator.state[TICK_TIME];


animator.play();
animator.pause();

const tick2 = animator.state[TICK_TIME];

animator.play();
animator.pause();

const tick3 = animator.state[TICK_TIME];

expect(tick1).to.be.equals(4);
expect(tick2).to.be.equals(4);
expect(tick3).to.be.equals(4);
});
it("should check paused", done => {
const animator = new Animator({
delay: 1,
Expand Down Expand Up @@ -288,6 +316,7 @@ describe("Animator Test", () => {
});
animator.play();
});

it("should check ended (delay)", done => {
const animator = new Animator({
delay: 1,
Expand Down

0 comments on commit 84dd631

Please sign in to comment.