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

Function describeDefaultProp

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

Source from the content-addressed store, hash-verified

310}
311
312function describeDefaultProp() {
313 // The hook API always uses { default: true } for render-driven updates.
314 // Some props can have default values (eg: onRest, config, etc), and
315 // other props may behave differently when { default: true } is used.
316 describe('when "default" prop is true', () => {
317 describe('and "from" prop is changed', () => {
318 describe('before the first animation', () => {
319 it('updates the current value', () => {
320 const props = { default: true, from: 1, to: 1 }
321 const spring = new SpringValue(props)
322
323 expect(spring.get()).toBe(1)
324 expect(spring.idle).toBeTruthy()
325
326 props.from = 0
327 spring.start(props)
328
329 expect(spring.get()).not.toBe(1)
330 expect(spring.idle).toBeFalsy()
331 })
332 })
333
334 describe('after the first animation', () => {
335 it('does not start animating', async () => {
336 const props = { default: true, from: 0, to: 2 }
337 const spring = new SpringValue(props)
338 await global.advanceUntilIdle()
339
340 props.from = 1
341 spring.start(props)
342
343 expect(spring.get()).toBe(2)
344 expect(spring.idle).toBeTruthy()
345 expect(spring.animation.from).toBe(1)
346 })
347
348 describe('and "reset" prop is true', () => {
349 it('starts at the "from" prop', async () => {
350 const props: any = { default: true, from: 0, to: 2 }
351 const spring = new SpringValue(props)
352 await global.advanceUntilIdle()
353
354 props.from = 1
355 props.reset = true
356 spring.start(props)
357
358 expect(spring.animation.from).toBe(1)
359 expect(spring.idle).toBeFalsy()
360 })
361 })
362 })
363 })
364 })
365
366 describe('when "default" prop is false', () => {
367 describe('and "from" prop is defined', () => {
368 it('updates the current value', () => {
369 const spring = new SpringValue(0)

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…