@@ -15,41 +15,7 @@ describe('SpringValue', () => {
1515 } )
1616
1717 describeProps ( )
18-
19- describe ( '"set" method' , ( ) => {
20- it ( 'stops the active animation' , async ( ) => {
21- const spring = new SpringValue ( 0 )
22- const promise = spring . start ( 1 )
23-
24- await advanceUntilValue ( spring , 0.5 )
25- spring . set ( 2 )
26-
27- expect ( spring . idle ) . toBeTruthy ( )
28- expect ( await promise ) . toMatchObject ( {
29- finished : false ,
30- value : 2 ,
31- } )
32- } )
33-
34- describe ( 'when a new value is passed' , ( ) => {
35- it ( 'calls the "onChange" prop' , ( ) => {
36- const onChange = jest . fn ( )
37- const spring = new SpringValue ( 0 , { onChange } )
38- spring . set ( 1 )
39- expect ( onChange ) . toBeCalledWith ( 1 , spring )
40- } )
41- it . todo ( 'wraps the "onChange" call with "batchedUpdates"' )
42- } )
43-
44- describe ( 'when the current value is passed' , ( ) => {
45- it ( 'skips the "onChange" call' , ( ) => {
46- const onChange = jest . fn ( )
47- const spring = new SpringValue ( 0 , { onChange } )
48- spring . set ( 0 )
49- expect ( onChange ) . not . toBeCalled ( )
50- } )
51- } )
52- } )
18+ describeMethods ( )
5319
5420 describeTarget ( 'another SpringValue' , from => {
5521 const node = new SpringValue ( from )
@@ -128,6 +94,43 @@ function describeConfigProp() {
12894 } )
12995}
13096
97+ function describeMethods ( ) {
98+ describe ( '"set" method' , ( ) => {
99+ it ( 'stops the active animation' , async ( ) => {
100+ const spring = new SpringValue ( 0 )
101+ const promise = spring . start ( 1 )
102+
103+ await advanceUntilValue ( spring , 0.5 )
104+ spring . set ( 2 )
105+
106+ expect ( spring . idle ) . toBeTruthy ( )
107+ expect ( await promise ) . toMatchObject ( {
108+ finished : false ,
109+ value : 2 ,
110+ } )
111+ } )
112+
113+ describe ( 'when a new value is passed' , ( ) => {
114+ it ( 'calls the "onChange" prop' , ( ) => {
115+ const onChange = jest . fn ( )
116+ const spring = new SpringValue ( 0 , { onChange } )
117+ spring . set ( 1 )
118+ expect ( onChange ) . toBeCalledWith ( 1 , spring )
119+ } )
120+ it . todo ( 'wraps the "onChange" call with "batchedUpdates"' )
121+ } )
122+
123+ describe ( 'when the current value is passed' , ( ) => {
124+ it ( 'skips the "onChange" call' , ( ) => {
125+ const onChange = jest . fn ( )
126+ const spring = new SpringValue ( 0 , { onChange } )
127+ spring . set ( 0 )
128+ expect ( onChange ) . not . toBeCalled ( )
129+ } )
130+ } )
131+ } )
132+ }
133+
131134/** The minimum requirements for testing a dynamic target */
132135type OpaqueTarget = {
133136 node : FrameValue
0 commit comments