Skip to content

Instantly share code, notes, and snippets.

@mattgperry
Created March 31, 2020 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattgperry/636638940cde9cff9fdfaef192c9af3a to your computer and use it in GitHub Desktop.
Save mattgperry/636638940cde9cff9fdfaef192c9af3a to your computer and use it in GitHub Desktop.
Framer Motion example test
test("drag handlers aren't frozen at drag session start", async () => {
let count = 0
const onDragEnd = deferred()
const Component = () => {
const [increment, setIncrement] = useState(1)
return (
<MockDrag>
<motion.div
drag
onDragStart={() => {
count += increment
setIncrement(2)
}}
onDrag={() => (count += increment)}
onDragEnd={() => {
count += increment + 1
onDragEnd.resolve()
}}
/>
</MockDrag>
)
}
const { container, rerender } = render(<Component />)
rerender(<Component />)
const pointer = await drag(container.firstChild).to(100, 100) // + 1 + 2 = 3
await frame.postRender() // + 2 = 5
await pointer.to(50, 50) // + 2 = 7
await frame.postRender() // + 2 = 9
pointer.end() // + 3 = 12
await onDragEnd.promise
expect(count).toBe(12)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment