Created
March 31, 2020 07:51
-
-
Save mattgperry/636638940cde9cff9fdfaef192c9af3a to your computer and use it in GitHub Desktop.
Framer Motion example test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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