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

Function describeImmediateProp

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

Source from the content-addressed store, hash-verified

459}
460
461function describeImmediateProp() {
462 describe('when "immediate" prop is true', () => {
463 it('still resolves the "start" promise', async () => {
464 const spring = new SpringValue(0)
465 const promise = spring.start(1, { immediate: true })
466 await global.advanceUntilIdle()
467 const result = await promise
468 expect(result.finished).toBe(true)
469 expect(result.value).toBe(1)
470 })
471
472 it('calls the "onStart" prop with finished: true', async () => {
473 const onStart = vi.fn()
474 const spring = new SpringValue(0)
475 spring.start(1, { immediate: true, onStart })
476 await global.advanceUntilIdle()
477 expect(onStart).toBeCalledTimes(1)
478 expect(onStart.mock.calls[0][0]).toMatchObject({
479 finished: true,
480 cancelled: false,
481 })
482 })
483
484 it('calls the "onRest" prop with finished: true', async () => {
485 const onRest = vi.fn()
486 const spring = new SpringValue(0)
487 spring.start(1, { immediate: true, onRest })
488 await global.advanceUntilIdle()
489 expect(onRest).toBeCalledTimes(1)
490 expect(onRest.mock.calls[0][0]).toMatchObject({
491 finished: true,
492 value: 1,
493 })
494 })
495
496 it('stops animating', async () => {
497 const spring = new SpringValue(0)
498 spring.start(2)
499 await global.advanceUntilValue(spring, 1)
500
501 // Use "immediate" to emulate the "stop" method. (see #884)
502 const value = spring.get()
503 spring.start(value, { immediate: true })
504
505 // The "immediate" prop waits until the next frame before going idle.
506 global.mockRaf.step()
507
508 expect(spring.idle).toBeTruthy()
509 expect(spring.get()).toBe(value)
510 })
511 })
512
513 describe('when "immediate: true" is followed by "immediate: false" in same frame', () => {
514 it('applies the immediate goal synchronously', () => {
515 const spring = new SpringValue(0)
516
517 // The immediate update is applied in the next frame.
518 spring.start({ to: 1, immediate: true })

Callers 1

describePropsFunction · 0.85

Calls 3

startMethod · 0.95
stepMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…