MCPcopy
hub / github.com/pmndrs/react-spring / describeToProp

Function describeToProp

packages/core/src/SpringValue.test.ts:183–251  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

181}
182
183function describeToProp() {
184 describe('when "to" prop is changed', () => {
185 it('resolves the "start" promise with (finished: false)', async () => {
186 const spring = new SpringValue(0)
187 const promise = spring.start(1)
188 await global.advance(5)
189 spring.start(2)
190 const result = await promise
191 expect(result.finished).toBe(false)
192 })
193
194 it('avoids calling the "onStart" prop', async () => {
195 const onStart = vi.fn()
196 const spring = new SpringValue(0)
197 spring.start(1, { onStart })
198 await global.advance(5)
199 expect(onStart).toBeCalledTimes(1)
200 spring.start(2)
201 await global.advanceUntilIdle()
202 expect(onStart).toBeCalledTimes(1)
203 })
204
205 it.todo('avoids calling the "onRest" prop')
206 })
207
208 describe('when "to" prop equals current value', () => {
209 it('cancels any pending animation', async () => {
210 const spring = new SpringValue(0)
211 spring.start(1)
212
213 // Prevent the animation to 1 (which hasn't started yet)
214 spring.start(0)
215
216 await global.advanceUntilIdle()
217 expect(global.getFrames(spring)).toEqual([])
218 })
219
220 it('avoids interrupting an active animation', async () => {
221 const spring = new SpringValue(0)
222 spring.start(1)
223 await global.advance()
224
225 const goal = spring.get()
226 spring.start(goal)
227 expect(spring.idle).toBeFalsy()
228
229 await global.advanceUntilIdle()
230 expect(spring.get()).toBe(goal)
231 expect(global.getFrames(spring)).toMatchSnapshot()
232 })
233 })
234
235 describe('when "to" prop is a function', () => {
236 describe('and "from" prop is defined', () => {
237 it('stops the active animation before "to" is called', () => {
238 const spring = new SpringValue({ from: 0, to: 1 })
239 global.mockRaf.step()
240

Callers 1

describePropsFunction · 0.85

Calls 4

startMethod · 0.95
stepMethod · 0.80
advanceMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…