Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move Controller test to live next to implementation
  • Loading branch information
jacobrask committed Feb 19, 2019
commit 9a385d775db0fe653304ae9e1221abe000f2516a
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@babel/preset-react": "7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@types/jest": "^24.0.0",
"@types/mock-raf": "^1.0.2",
"@types/react": "16.8.2",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "24.1.0",
Expand Down
48 changes: 48 additions & 0 deletions src/animated/Controller.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import createMockRaf from 'mock-raf'
import Controller from '../animated/Controller'
import { Globals } from '../targets/web'

test('update simple value', () => {
const mockRaf = createMockRaf()
Globals.injectFrame(mockRaf.raf, mockRaf.cancel)
Globals.injectNow(mockRaf.now)

const ctrl = new Controller() as any
ctrl.update({ x: 0 })
ctrl.start()
expect(ctrl.getValues().x.getValue()).toBe(0)

ctrl.update({ x: 100, y: 50 })
expect(ctrl.getValues().x.getValue()).toBe(0)

ctrl.start()

mockRaf.step({ count: 10 })
expect(ctrl.getValues().x.getValue()).toBeCloseTo(56.4)

mockRaf.step({ count: 100 })
expect(ctrl.getValues().x.getValue()).toBe(100)
})

test('update array value', () => {
const mockRaf = createMockRaf()
Globals.injectFrame(mockRaf.raf, mockRaf.cancel)
Globals.injectNow(mockRaf.now)

const ctrl = new Controller() as any
ctrl.update({ x: [0, 0] })
ctrl.start()
expect(ctrl.getValues().x.getValue()).toEqual([0, 0])

ctrl.update({ x: [10, 20] })
expect(ctrl.getValues().x.getValue()).toEqual([0, 0])

ctrl.start()

mockRaf.step({ count: 10 })
expect(ctrl.getValues().x.getValue()[0]).toBeCloseTo(5.64)
expect(ctrl.getValues().x.getValue()[1]).toBeCloseTo(11.28)

mockRaf.step({ count: 100 })
expect(ctrl.getValues().x.getValue()).toEqual([10, 20])
})
27 changes: 0 additions & 27 deletions src/tests/controller.test.js

This file was deleted.

5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,11 @@
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.0.tgz#848492026c327b3548d92be0352a545c36a21e8a"
integrity sha512-kOafJnUTnMd7/OfEO/x3I47EHswNjn+dbz9qk3mtonr1RvKT+1FGVxnxAx08I9K8Tl7j9hpoJRE7OCf+t10fng==

"@types/mock-raf@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@types/mock-raf/-/mock-raf-1.0.2.tgz#de0df16b1cbe2475cb1a4680a19f344f386d8252"
integrity sha1-3g3xaxy+JHXLGkaAoZ80TzhtglI=

"@types/node@*":
version "10.12.24"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.24.tgz#b13564af612a22a20b5d95ca40f1bffb3af315cf"
Expand Down