()
| 274 | } |
| 275 | |
| 276 | function describeResetProp() { |
| 277 | describe('when "reset" prop is true', () => { |
| 278 | it('calls "onRest" before jumping back to its "from" value', async () => { |
| 279 | const onRest = vi.fn((result: any) => { |
| 280 | expect(result.value).not.toBe(0) |
| 281 | }) |
| 282 | |
| 283 | const spring = new SpringValue({ from: 0, to: 1, onRest }) |
| 284 | global.mockRaf.step() |
| 285 | |
| 286 | spring.start({ reset: true }) |
| 287 | |
| 288 | expect(onRest).toHaveBeenCalled() |
| 289 | expect(spring.get()).toBe(0) |
| 290 | }) |
| 291 | |
| 292 | it('resolves the "start" promise with (finished: false)', async () => { |
| 293 | const spring = new SpringValue<number>() |
| 294 | const promise = spring.start({ from: 0, to: 1 }) |
| 295 | await global.advance(5) |
| 296 | spring.start({ reset: true }) |
| 297 | const result = await promise |
| 298 | expect(result.finished).toBe(false) |
| 299 | }) |
| 300 | |
| 301 | it('calls the "onRest" prop with (finished: false)', async () => { |
| 302 | const onRest = vi.fn() |
| 303 | const spring = new SpringValue({ from: 0, to: 1, onRest }) |
| 304 | await global.advance(5) |
| 305 | spring.start({ reset: true }) |
| 306 | expect(onRest).toBeCalledTimes(1) |
| 307 | expect(onRest.mock.calls[0][0]).toMatchObject({ finished: false }) |
| 308 | }) |
| 309 | }) |
| 310 | } |
| 311 | |
| 312 | function describeDefaultProp() { |
| 313 | // The hook API always uses { default: true } for render-driven updates. |
no test coverage detected
searching dependent graphs…