-
-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44744e0
commit 624003c
Showing
3 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { motionValue } from "../" | ||
import { animate } from "../../animation/animate" | ||
|
||
describe("motionValue", () => { | ||
test("change event fires when value changes", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("change", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
value.set(1) | ||
expect(callback).toBeCalledTimes(1) | ||
value.set(1) | ||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("renderRequest event fires", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("renderRequest", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
value.set(1) | ||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("animationStart event fires", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("animationStart", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
|
||
animate(value, 2) | ||
|
||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("animationCancel event fires", () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("animationCancel", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
|
||
animate(value, 1) | ||
animate(value, 2) | ||
|
||
expect(callback).toBeCalledTimes(1) | ||
}) | ||
|
||
test("animationComplete event fires", async () => { | ||
const value = motionValue(0) | ||
const callback = jest.fn() | ||
|
||
value.on("animationComplete", callback) | ||
|
||
expect(callback).not.toBeCalled() | ||
|
||
animate(value, 1, { duration: 0.01 }) | ||
|
||
return new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
expect(callback).toBeCalledTimes(1) | ||
resolve() | ||
}, 100) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters