Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@react-spring/mock-raf
Advanced tools
Readme
A simple mock for requestAnimationFrame
testing with fake timers.
Adapted with gratitude from react-motion
.
To use with jest
/jasmine
and react-spring
:
import createMockRaf from '@react-spring/mock-raf'
import { Globals, FrameLoop, SpringValue } from 'react-spring'
let mockRaf
beforeEach(() => {
mockRaf = createMockRaf()
Globals.assign({
now: mockRaf.now,
performanceNow: mockRaf.now,
requestAnimationFrame: mockRaf.raf,
cancelAnimationFrame: mockRaf.cancel,
frameLoop: new FrameLoop(),
})
})
it('animates from 0 to 1', () => {
const value = new SpringValue(0)
value.start(1)
expect(value.get()).toBe(0)
mockRaf.flush()
expect(value.get()).toBe(1)
})
createMockRaf()
Creates a mockRaf
instance, exposing the functions you'll use to interact with the mock.
Returns:
const mockRaf = createMockRaf()
now()
Returns the current now
value of the mock. Starts at 0 and increases with each step()
taken. Useful for stubbing out performance.now()
or a polyfill when using requestAnimationFrame
with timers.
raf()
Replacement for requestAnimationFrame
or a polyfill. Adds a callback to be fired on the next step.
cancel()
Replacement for cancelAnimationFrame
or a polyfill. Removes all currently scheduled requestAnimationFrame
callbacks from the queue.
flush()
Continuously iterate the requestAnimationFrame
queue until empty.
Useful for jumping to the end of an animation (or group of animations).
step(options)
Takes requestAnimationFrame
steps. Fires currently queued callbacks for each step and increments now
time for each step. The primary way to interact with a mockRaf
instance for testing.
step()
takes an optional options
object:
time
Type: Number
Default: 1000 / 60
The time that should pass during each requestAnimationFrame
step in milliseconds. Default is roughly equivalent to default browser behavior.
count
Type: Number
Default: 1
The number of steps to take.
FAQs
A simple mock for requestAnimationFrame testing with fake timers.
The npm package @react-spring/mock-raf receives a total of 2,171 weekly downloads. As such, @react-spring/mock-raf popularity was classified as popular.
We found that @react-spring/mock-raf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.