Skip to content

Commit 9a385d7

Browse files
committed
Move Controller test to live next to implementation
1 parent 767d601 commit 9a385d7

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@babel/preset-react": "7.0.0",
7171
"@babel/preset-typescript": "^7.1.0",
7272
"@types/jest": "^24.0.0",
73+
"@types/mock-raf": "^1.0.2",
7374
"@types/react": "16.8.2",
7475
"babel-core": "7.0.0-bridge.0",
7576
"babel-jest": "24.1.0",

src/animated/Controller.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import createMockRaf from 'mock-raf'
2+
import Controller from '../animated/Controller'
3+
import { Globals } from '../targets/web'
4+
5+
test('update simple value', () => {
6+
const mockRaf = createMockRaf()
7+
Globals.injectFrame(mockRaf.raf, mockRaf.cancel)
8+
Globals.injectNow(mockRaf.now)
9+
10+
const ctrl = new Controller() as any
11+
ctrl.update({ x: 0 })
12+
ctrl.start()
13+
expect(ctrl.getValues().x.getValue()).toBe(0)
14+
15+
ctrl.update({ x: 100, y: 50 })
16+
expect(ctrl.getValues().x.getValue()).toBe(0)
17+
18+
ctrl.start()
19+
20+
mockRaf.step({ count: 10 })
21+
expect(ctrl.getValues().x.getValue()).toBeCloseTo(56.4)
22+
23+
mockRaf.step({ count: 100 })
24+
expect(ctrl.getValues().x.getValue()).toBe(100)
25+
})
26+
27+
test('update array value', () => {
28+
const mockRaf = createMockRaf()
29+
Globals.injectFrame(mockRaf.raf, mockRaf.cancel)
30+
Globals.injectNow(mockRaf.now)
31+
32+
const ctrl = new Controller() as any
33+
ctrl.update({ x: [0, 0] })
34+
ctrl.start()
35+
expect(ctrl.getValues().x.getValue()).toEqual([0, 0])
36+
37+
ctrl.update({ x: [10, 20] })
38+
expect(ctrl.getValues().x.getValue()).toEqual([0, 0])
39+
40+
ctrl.start()
41+
42+
mockRaf.step({ count: 10 })
43+
expect(ctrl.getValues().x.getValue()[0]).toBeCloseTo(5.64)
44+
expect(ctrl.getValues().x.getValue()[1]).toBeCloseTo(11.28)
45+
46+
mockRaf.step({ count: 100 })
47+
expect(ctrl.getValues().x.getValue()).toEqual([10, 20])
48+
})

src/tests/controller.test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,11 @@
882882
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.0.tgz#848492026c327b3548d92be0352a545c36a21e8a"
883883
integrity sha512-kOafJnUTnMd7/OfEO/x3I47EHswNjn+dbz9qk3mtonr1RvKT+1FGVxnxAx08I9K8Tl7j9hpoJRE7OCf+t10fng==
884884

885+
"@types/mock-raf@^1.0.2":
886+
version "1.0.2"
887+
resolved "https://registry.yarnpkg.com/@types/mock-raf/-/mock-raf-1.0.2.tgz#de0df16b1cbe2475cb1a4680a19f344f386d8252"
888+
integrity sha1-3g3xaxy+JHXLGkaAoZ80TzhtglI=
889+
885890
"@types/node@*":
886891
version "10.12.24"
887892
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.24.tgz#b13564af612a22a20b5d95ca40f1bffb3af315cf"

0 commit comments

Comments
 (0)