Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 592b337

Browse files
chore: Add framer-motion example (#416)
1 parent ab5ca4c commit 592b337

File tree

8 files changed

+137
-7
lines changed

8 files changed

+137
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Spec | Description
186186
[select React component](cypress/component/advanced/react-book-example/src/components/ProductsList.spec.js) | Uses [cypress-react-selector](https://github.com/abhinaba-ghosh/cypress-react-selector) to find DOM elements using React component name and state values
187187
[lazy-loaded](cypress/component/advanced/lazy-loaded-suspense) | Uses multiple chunks and async components with `React.lazy` + `React.Suspense`.
188188
[i18n](cypress/component/advanced/i18n) | Uses[react-i18next](https://react.i18next.com/) for localizaiton.
189+
[framer-motion](cypress/component/advanced/framer-motion) | Uses [framer motion](https://www.framer.com/motion/) for javascript-based animation.
189190
<!-- prettier-ignore-end -->
190191

191192
### Full examples

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ workflows:
6161
install-command: npm install
6262
verify-command: echo 'Already verified'
6363
no-workspace: true
64-
working_directory: examples/using-babel-typesceript
64+
working_directory: examples/using-babel-typescript
6565
command: npm test
6666
store_artifacts: true
6767

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
body {
2+
width: 100vw;
3+
height: 100vh;
4+
background: linear-gradient(180deg, #d309e1 0%, rgb(156, 26, 255) 100%);
5+
overflow: hidden;
6+
padding: 0;
7+
margin: 0;
8+
display: flex;
9+
justify-content: center;
10+
align-items: center;
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react'
2+
import { Motion } from './Motion'
3+
import { mount } from 'cypress-react-unit-test'
4+
5+
describe('framer-motion', () => {
6+
it('Renders component and retries the animation', () => {
7+
mount(<Motion />)
8+
9+
cy.get("[data-testid='motion']").should('have.css', 'border-radius', '50%')
10+
cy.get("[data-testid='motion']").should('have.css', 'border-radius', '20%')
11+
})
12+
13+
it('Mocks setTimeout and requestAnimationFrame', () => {
14+
cy.clock()
15+
mount(<Motion />)
16+
17+
// CI is slow, so check only the approximate values
18+
cy.tick(800)
19+
cy.get("[data-testid='motion']").within(element => {
20+
expect(parseInt(element.css('borderRadius'))).to.equal(43)
21+
})
22+
23+
cy.tick(100)
24+
cy.get("[data-testid='motion']").within(element => {
25+
expect(parseInt(element.css('borderRadius'))).to.equal(48)
26+
})
27+
})
28+
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import './Motion.css'
2+
import * as React from 'react'
3+
import { motion } from 'framer-motion'
4+
5+
export const Motion = () => {
6+
return (
7+
<motion.div
8+
data-testid="motion"
9+
style={{ width: 100, height: 100, backgroundColor: 'white' }}
10+
animate={{
11+
scale: [1, 2, 2, 1, 1],
12+
rotate: [0, 0, 270, 270, 0],
13+
borderRadius: ['20%', '20%', '50%', '50%', '20%'],
14+
}}
15+
transition={{
16+
duration: 2,
17+
ease: 'easeInOut',
18+
times: [0, 0.2, 0.5, 0.8, 1],
19+
loop: false,
20+
repeatDelay: 1,
21+
}}
22+
/>
23+
)
24+
}

examples/using-babel-typescript/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "example-using-babel",
3-
"description": "Component testing for projects using Babel config",
2+
"name": "example-using-babel-typescript",
3+
"description": "Component testing for TypeScript projects using Babel config",
44
"private": true,
55
"scripts": {
6-
"test": "node ../../scripts/cypress-expect run --passing 17",
6+
"test": "node ../../scripts/cypress-expect run --passing 1",
77
"cy:open": "../../node_modules/.bin/cypress open"
88
},
99
"devDependencies": {

package-lock.json

Lines changed: 68 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
"babel-plugin-istanbul": "6.0.0",
135135
"debug": "4.1.1",
136136
"find-webpack": "2.0.0",
137+
"framer-motion": "2.6.13",
137138
"i18next": "19.7.0",
138139
"mime-types": "2.1.26",
139140
"react-i18next": "11.7.2",

0 commit comments

Comments
 (0)