()
| 548 | } |
| 549 | |
| 550 | function describeConfigProp() { |
| 551 | describe('the "config" prop', () => { |
| 552 | it('resets the velocity when "to" changes', () => { |
| 553 | const spring = new SpringValue(0) |
| 554 | spring.start({ to: 100, config: { velocity: 10 } }) |
| 555 | |
| 556 | const { config } = spring.animation |
| 557 | expect(config.velocity).toBe(10) |
| 558 | |
| 559 | // Preserve velocity if "to" did not change. |
| 560 | spring.start({ config: { tension: 200 } }) |
| 561 | expect(config.velocity).toBe(10) |
| 562 | |
| 563 | spring.start({ to: 200 }) |
| 564 | expect(config.velocity).toBe(0) |
| 565 | }) |
| 566 | it('preserves velocity across "to" updates when decay is set', () => { |
| 567 | const spring = new SpringValue(0) |
| 568 | spring.start({ to: 100, config: { velocity: 10, decay: true } }) |
| 569 | |
| 570 | const { config } = spring.animation |
| 571 | expect(config.velocity).toBe(10) |
| 572 | |
| 573 | // Retargeting must NOT wipe velocity for decay animations. |
| 574 | spring.start({ to: 200, config: { decay: true } }) |
| 575 | expect(config.velocity).toBe(10) |
| 576 | }) |
| 577 | it('decay continues animating after retarget (#1843)', async () => { |
| 578 | const spring = new SpringValue(0) |
| 579 | spring.start(100, { config: { velocity: 10, decay: 0.48 } }) |
| 580 | await global.advanceUntilIdle() |
| 581 | const firstRest = spring.get() |
| 582 | expect(firstRest).toBeGreaterThan(1) |
| 583 | |
| 584 | // Simulate a mid-gesture retarget with a new velocity. |
| 585 | spring.start(200, { config: { velocity: 5, decay: 0.48 } }) |
| 586 | await global.advanceUntilIdle() |
| 587 | expect(spring.get()).toBeGreaterThan(firstRest) |
| 588 | }) |
| 589 | describe('when "damping" is 1.0', () => { |
| 590 | it('should prevent bouncing', async () => { |
| 591 | const spring = new SpringValue(0) |
| 592 | spring.start(1, { |
| 593 | config: { frequency: 1.5, damping: 1 }, |
| 594 | }) |
| 595 | await global.advanceUntilIdle() |
| 596 | expect(global.countBounces(spring)).toBe(0) |
| 597 | }) |
| 598 | }) |
| 599 | describe('when "damping" is less than 1.0', () => { |
| 600 | it('should bounce', async () => { |
| 601 | const spring = new SpringValue(0) |
| 602 | spring.start(1, { |
| 603 | config: { frequency: 1.5, damping: 0.5 }, |
| 604 | }) |
| 605 | await global.advanceUntilIdle() |
| 606 | expect(global.countBounces(spring)).toBeGreaterThan(0) |
| 607 | }) |
no test coverage detected
searching dependent graphs…