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

Function describeResetProp

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

Source from the content-addressed store, hash-verified

274}
275
276function 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
312function describeDefaultProp() {
313 // The hook API always uses { default: true } for render-driven updates.

Callers 1

describePropsFunction · 0.85

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…