Skip to content

Commit 11aedd4

Browse files
committed
chore: wrap Controller tests in a describe block
1 parent 38a7f2b commit 11aedd4

File tree

2 files changed

+182
-180
lines changed

2 files changed

+182
-180
lines changed
Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
11
import { Controller } from './Controller'
22

3-
it('can animate a number', () => {
4-
const ctrl = new Controller({ x: 0 })
5-
ctrl.start({ x: 100 })
3+
describe('Controller', () => {
4+
it('can animate a number', () => {
5+
const ctrl = new Controller({ x: 0 })
6+
ctrl.start({ x: 100 })
67

7-
const frames = getFrames(ctrl)
8-
expect(frames).toMatchSnapshot()
8+
const frames = getFrames(ctrl)
9+
expect(frames).toMatchSnapshot()
910

10-
// The first frame should *not* be the from value.
11-
expect(frames[0]).not.toEqual({ x: 0 })
11+
// The first frame should *not* be the from value.
12+
expect(frames[0]).not.toEqual({ x: 0 })
1213

13-
// The last frame should be the goal value.
14-
expect(frames.slice(-1)[0]).toEqual({ x: 100 })
15-
})
14+
// The last frame should be the goal value.
15+
expect(frames.slice(-1)[0]).toEqual({ x: 100 })
16+
})
1617

17-
it('can animate an array of numbers', () => {
18-
const config = { precision: 0.005 }
19-
const ctrl = new Controller<{ x: [number, number] }>({ x: [1, 2], config })
20-
ctrl.start({ x: [5, 10] })
18+
it('can animate an array of numbers', () => {
19+
const config = { precision: 0.005 }
20+
const ctrl = new Controller<{ x: [number, number] }>({ x: [1, 2], config })
21+
ctrl.start({ x: [5, 10] })
2122

22-
const frames = getFrames(ctrl)
23-
expect(frames).toMatchSnapshot()
23+
const frames = getFrames(ctrl)
24+
expect(frames).toMatchSnapshot()
2425

25-
// The last frame should be the goal value.
26-
expect(frames.slice(-1)[0]).toEqual({ x: [5, 10] })
26+
// The last frame should be the goal value.
27+
expect(frames.slice(-1)[0]).toEqual({ x: [5, 10] })
2728

28-
// The 2nd value is always ~2x the 1st value (within the defined precision).
29-
const factors = frames.map(frame => frame.x[1] / frame.x[0])
30-
expect(
31-
factors.every(factor => Math.abs(2 - factor) < config.precision)
32-
).toBeTruthy()
33-
})
29+
// The 2nd value is always ~2x the 1st value (within the defined precision).
30+
const factors = frames.map(frame => frame.x[1] / frame.x[0])
31+
expect(
32+
factors.every(factor => Math.abs(2 - factor) < config.precision)
33+
).toBeTruthy()
34+
})
3435

35-
describe('async "to" prop', () => {
36-
it('acts strangely without the "from" prop', async () => {
37-
const ctrl = new Controller<{ x: number }>()
38-
ctrl.start({
39-
to: async update => {
40-
// The spring does not exist yet!
41-
expect(ctrl.get('x')).toBeUndefined()
42-
43-
// Any values passed here are treated as "from" values,
44-
// because no "from" prop was ever given.
45-
update({ x: 1 })
46-
// Now the spring exists!
47-
expect(ctrl.get('x')).toBeDefined()
48-
// But the spring is idle!
49-
expect(ctrl.get('x').idle).toBeTruthy()
50-
51-
// This call *will* start an animation!
52-
update({ x: 2 })
53-
expect(ctrl.get('x').idle).toBeFalsy()
54-
},
36+
describe('when the "to" prop is an async function', () => {
37+
it('acts strangely without the "from" prop', async () => {
38+
const ctrl = new Controller<{ x: number }>()
39+
ctrl.start({
40+
to: async update => {
41+
// The spring does not exist yet!
42+
expect(ctrl.get('x')).toBeUndefined()
43+
44+
// Any values passed here are treated as "from" values,
45+
// because no "from" prop was ever given.
46+
update({ x: 1 })
47+
// Now the spring exists!
48+
expect(ctrl.get('x')).toBeDefined()
49+
// But the spring is idle!
50+
expect(ctrl.get('x').idle).toBeTruthy()
51+
52+
// This call *will* start an animation!
53+
update({ x: 2 })
54+
expect(ctrl.get('x').idle).toBeFalsy()
55+
},
56+
})
57+
58+
// Since we call `update` twice, frames are generated!
59+
expect(await getAsyncFrames(ctrl)).toMatchSnapshot()
5560
})
56-
57-
// Since we call `update` twice, frames are generated!
58-
expect(await getAsyncFrames(ctrl)).toMatchSnapshot()
5961
})
6062
})

packages/core/src/__snapshots__/Controller.test.ts.snap

Lines changed: 133 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`async "to" prop acts strangely without the "from" prop 1`] = `
4-
Array [
5-
Object {
6-
"x": 1.0226348433078583,
7-
},
8-
Object {
9-
"x": 1.0761552889499395,
10-
},
11-
Object {
12-
"x": 1.1472729545687759,
13-
},
14-
Object {
15-
"x": 1.226793329378144,
16-
},
17-
Object {
18-
"x": 1.3085053191603682,
19-
},
20-
Object {
21-
"x": 1.3883524421610094,
22-
},
23-
Object {
24-
"x": 1.4638171205392543,
25-
},
26-
Object {
27-
"x": 1.5334657448036912,
28-
},
29-
Object {
30-
"x": 1.5966146523130327,
31-
},
32-
Object {
33-
"x": 1.6530867180317823,
34-
},
35-
Object {
36-
"x": 1.7030355736424132,
37-
},
38-
Object {
39-
"x": 1.74682006574163,
40-
},
41-
Object {
42-
"x": 1.7849158337229636,
43-
},
44-
Object {
45-
"x": 1.817854140674256,
46-
},
47-
Object {
48-
"x": 1.8461805634019814,
49-
},
50-
Object {
51-
"x": 1.870428023277061,
52-
},
53-
Object {
54-
"x": 1.8911000586164695,
55-
},
56-
Object {
57-
"x": 1.9086613098839855,
58-
},
59-
Object {
60-
"x": 1.9235329941206056,
61-
},
62-
Object {
63-
"x": 1.9360917483504718,
64-
},
65-
Object {
66-
"x": 1.9466706719880824,
67-
},
68-
Object {
69-
"x": 1.9555617327559878,
70-
},
71-
Object {
72-
"x": 1.9630189477450264,
73-
},
74-
Object {
75-
"x": 1.9692619326731133,
76-
},
77-
Object {
78-
"x": 1.9744795445908405,
79-
},
80-
Object {
81-
"x": 1.9788334387327189,
82-
},
83-
Object {
84-
"x": 1.9824614283710786,
85-
},
86-
Object {
87-
"x": 1.9854805845242978,
88-
},
89-
Object {
90-
"x": 1.9879900455631967,
91-
},
92-
Object {
93-
"x": 1.9900735291663625,
94-
},
95-
Object {
96-
"x": 1.991801553694958,
97-
},
98-
Object {
99-
"x": 1.9932333851170567,
100-
},
101-
Object {
102-
"x": 1.9944187307560275,
103-
},
104-
Object {
105-
"x": 1.9953992035746602,
106-
},
107-
Object {
108-
"x": 1.9962095813165261,
109-
},
110-
Object {
111-
"x": 1.9968788842438259,
112-
},
113-
Object {
114-
"x": 1.997431293890262,
115-
},
116-
Object {
117-
"x": 1.9978869335076728,
118-
},
119-
Object {
120-
"x": 1.998262528947063,
121-
},
122-
Object {
123-
"x": 1.9985719667273445,
124-
},
125-
Object {
126-
"x": 1.9988267641056732,
127-
},
128-
Object {
129-
"x": 2,
130-
},
131-
]
132-
`;
133-
134-
exports[`can animate a number 1`] = `
3+
exports[`Controller can animate a number 1`] = `
1354
Array [
1365
Object {
1376
"x": 2.263484330785799,
@@ -262,7 +131,7 @@ Array [
262131
]
263132
`;
264133

265-
exports[`can animate an array of numbers 1`] = `
134+
exports[`Controller can animate an array of numbers 1`] = `
266135
Array [
267136
Object {
268137
"x": Array [
@@ -536,3 +405,134 @@ Array [
536405
},
537406
]
538407
`;
408+
409+
exports[`Controller when the "to" prop is an async function acts strangely without the "from" prop 1`] = `
410+
Array [
411+
Object {
412+
"x": 1.0226348433078583,
413+
},
414+
Object {
415+
"x": 1.0761552889499395,
416+
},
417+
Object {
418+
"x": 1.1472729545687759,
419+
},
420+
Object {
421+
"x": 1.226793329378144,
422+
},
423+
Object {
424+
"x": 1.3085053191603682,
425+
},
426+
Object {
427+
"x": 1.3883524421610094,
428+
},
429+
Object {
430+
"x": 1.4638171205392543,
431+
},
432+
Object {
433+
"x": 1.5334657448036912,
434+
},
435+
Object {
436+
"x": 1.5966146523130327,
437+
},
438+
Object {
439+
"x": 1.6530867180317823,
440+
},
441+
Object {
442+
"x": 1.7030355736424132,
443+
},
444+
Object {
445+
"x": 1.74682006574163,
446+
},
447+
Object {
448+
"x": 1.7849158337229636,
449+
},
450+
Object {
451+
"x": 1.817854140674256,
452+
},
453+
Object {
454+
"x": 1.8461805634019814,
455+
},
456+
Object {
457+
"x": 1.870428023277061,
458+
},
459+
Object {
460+
"x": 1.8911000586164695,
461+
},
462+
Object {
463+
"x": 1.9086613098839855,
464+
},
465+
Object {
466+
"x": 1.9235329941206056,
467+
},
468+
Object {
469+
"x": 1.9360917483504718,
470+
},
471+
Object {
472+
"x": 1.9466706719880824,
473+
},
474+
Object {
475+
"x": 1.9555617327559878,
476+
},
477+
Object {
478+
"x": 1.9630189477450264,
479+
},
480+
Object {
481+
"x": 1.9692619326731133,
482+
},
483+
Object {
484+
"x": 1.9744795445908405,
485+
},
486+
Object {
487+
"x": 1.9788334387327189,
488+
},
489+
Object {
490+
"x": 1.9824614283710786,
491+
},
492+
Object {
493+
"x": 1.9854805845242978,
494+
},
495+
Object {
496+
"x": 1.9879900455631967,
497+
},
498+
Object {
499+
"x": 1.9900735291663625,
500+
},
501+
Object {
502+
"x": 1.991801553694958,
503+
},
504+
Object {
505+
"x": 1.9932333851170567,
506+
},
507+
Object {
508+
"x": 1.9944187307560275,
509+
},
510+
Object {
511+
"x": 1.9953992035746602,
512+
},
513+
Object {
514+
"x": 1.9962095813165261,
515+
},
516+
Object {
517+
"x": 1.9968788842438259,
518+
},
519+
Object {
520+
"x": 1.997431293890262,
521+
},
522+
Object {
523+
"x": 1.9978869335076728,
524+
},
525+
Object {
526+
"x": 1.998262528947063,
527+
},
528+
Object {
529+
"x": 1.9985719667273445,
530+
},
531+
Object {
532+
"x": 1.9988267641056732,
533+
},
534+
Object {
535+
"x": 2,
536+
},
537+
]
538+
`;

0 commit comments

Comments
 (0)