Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into fix/built-in-glamorous-components_properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds authored Feb 12, 2018
2 parents a821469 + b843c27 commit 5942dad
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 9 deletions.
30 changes: 30 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,36 @@
"contributions": [
"ideas"
]
},
{
"login": "exah",
"name": "John Grishin",
"avatar_url": "https://avatars1.githubusercontent.com/u/442932?v=4",
"profile": "http://johngrish.in",
"contributions": [
"bug",
"code",
"test"
]
},
{
"login": "tikotzky",
"name": "Mordy Tikotzky",
"avatar_url": "https://avatars3.githubusercontent.com/u/200528?v=4",
"profile": "https://github.com/tikotzky",
"contributions": [
"bug",
"code"
]
},
{
"login": "penx",
"name": "Alasdair McLeay",
"avatar_url": "https://avatars3.githubusercontent.com/u/1027024?v=4",
"profile": "https://github.com/penx",
"contributions": [
"example"
]
}
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![downloads][downloads-badge]][npmcharts]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-56-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-59-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Chat][chat-badge]][chat]
[![Code of Conduct][coc-badge]][coc]
Expand Down Expand Up @@ -162,6 +162,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [<img src="https://avatars3.githubusercontent.com/u/22868432?v=3" width="100px;"/><br /><sub><b>Lufty Wiranda</b></sub>](http://instagram.com/luftywiranda13)<br />[💻](https://github.com/paypal/glamorous/commits?author=luftywiranda13 "Code") | [<img src="https://avatars3.githubusercontent.com/u/3208863?v=3" width="100px;"/><br /><sub><b>Ansuman Shah</b></sub>](https://github.com/ansumanshah)<br />[💻](https://github.com/paypal/glamorous/commits?author=ansumanshah "Code") [📖](https://github.com/paypal/glamorous/commits?author=ansumanshah "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/11598?v=3" width="100px;"/><br /><sub><b>Travis LaDuke</b></sub>](http://-)<br />[💡](#example-laduke "Examples") | [<img src="https://avatars2.githubusercontent.com/u/11290953?v=3" width="100px;"/><br /><sub><b>Aydın Çağrı Dumlu</b></sub>](https://github.com/acgrdumlu)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Aacgrdumlu "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=acgrdumlu "Code") | [<img src="https://avatars2.githubusercontent.com/u/1383861?v=3" width="100px;"/><br /><sub><b>Maja Wichrowska</b></sub>](https://github.com/majapw)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Amajapw "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/6845263?v=3" width="100px;"/><br /><sub><b>Tom Liu</b></sub>](https://github.com/gt3240)<br />[📖](https://github.com/paypal/glamorous/commits?author=gt3240 "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/1863771?v=3" width="100px;"/><br /><sub><b>Siddharth Kshetrapal</b></sub>](https://github.com/siddharthkp)<br />[⚠️](https://github.com/paypal/glamorous/commits?author=siddharthkp "Tests") [🔧](#tool-siddharthkp "Tools") |
| [<img src="https://avatars2.githubusercontent.com/u/5257243?v=3" width="100px;"/><br /><sub><b>WillowHQ</b></sub>](https://github.com/WillowHQ)<br />[📖](https://github.com/paypal/glamorous/commits?author=WillowHQ "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/12202757?v=4" width="100px;"/><br /><sub><b>Mohammad Rajabifard</b></sub>](https://tarino.ir)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Amorajabi "Bug reports") [📖](https://github.com/paypal/glamorous/commits?author=morajabi "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/17005317?v=3" width="100px;"/><br /><sub><b>Omar Albacha</b></sub>](https://github.com/Oalbacha)<br />[💻](https://github.com/paypal/glamorous/commits?author=Oalbacha "Code") [📖](https://github.com/paypal/glamorous/commits?author=Oalbacha "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/28659384?v=3" width="100px;"/><br /><sub><b>tdeschryver</b></sub>](https://github.com/tdeschryver)<br />[💻](https://github.com/paypal/glamorous/commits?author=tdeschryver "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=tdeschryver "Tests") | [<img src="https://avatars0.githubusercontent.com/u/4955191?v=4" width="100px;"/><br /><sub><b>Dylan Mozlowski</b></sub>](https://github.com/DylanMoz)<br />[💻](https://github.com/paypal/glamorous/commits?author=DylanMoz "Code") | [<img src="https://avatars2.githubusercontent.com/u/3275424?v=4" width="100px;"/><br /><sub><b>andretshurotshka</b></sub>](https://github.com/goodmind)<br />[💻](https://github.com/paypal/glamorous/commits?author=goodmind "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=goodmind "Tests") | [<img src="https://avatars3.githubusercontent.com/u/12836237?v=4" width="100px;"/><br /><sub><b>Danila</b></sub>](https://github.com/O4epegb)<br />[⚠️](https://github.com/paypal/glamorous/commits?author=O4epegb "Tests") |
| [<img src="https://avatars3.githubusercontent.com/u/12473268?v=4" width="100px;"/><br /><sub><b>Junyoung Clare Jang</b></sub>](http://ailrun.github.io/)<br />[💻](https://github.com/paypal/glamorous/commits?author=Ailrun "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=Ailrun "Tests") | [<img src="https://avatars2.githubusercontent.com/u/897575?v=4" width="100px;"/><br /><sub><b>Björn Ricks</b></sub>](https://twitter.com/bjoernricks)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Abjoernricks "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=bjoernricks "Code") [📖](https://github.com/paypal/glamorous/commits?author=bjoernricks "Documentation") [⚠️](https://github.com/paypal/glamorous/commits?author=bjoernricks "Tests") | [<img src="https://avatars0.githubusercontent.com/u/4934193?v=4" width="100px;"/><br /><sub><b>Tyler Deitz</b></sub>](http://tylerdeitz.com)<br />[💻](https://github.com/paypal/glamorous/commits?author=tvler "Code") | [<img src="https://avatars2.githubusercontent.com/u/16104985?v=4" width="100px;"/><br /><sub><b>Shovan Chatterjee</b></sub>](https://twitter.com/shovan_ch)<br />[📖](https://github.com/paypal/glamorous/commits?author=shovanch "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/6839660?v=4" width="100px;"/><br /><sub><b>johnjessewood</b></sub>](https://github.com/johnjesse)<br />[💻](https://github.com/paypal/glamorous/commits?author=johnjesse "Code") | [<img src="https://avatars3.githubusercontent.com/u/856386?v=4" width="100px;"/><br /><sub><b>Daniel</b></sub>](https://www.danielberndt.net)<br />[💻](https://github.com/paypal/glamorous/commits?author=danielberndt "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=danielberndt "Tests") | [<img src="https://avatars0.githubusercontent.com/u/174864?v=4" width="100px;"/><br /><sub><b>Ken Powers</b></sub>](https://knpw.rs)<br />[🤔](#ideas-knpwrs "Ideas, Planning, & Feedback") |
| [<img src="https://avatars1.githubusercontent.com/u/442932?v=4" width="100px;"/><br /><sub><b>John Grishin</b></sub>](http://johngrish.in)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Aexah "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=exah "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=exah "Tests") | [<img src="https://avatars3.githubusercontent.com/u/200528?v=4" width="100px;"/><br /><sub><b>Mordy Tikotzky</b></sub>](https://github.com/tikotzky)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Atikotzky "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=tikotzky "Code") | [<img src="https://avatars3.githubusercontent.com/u/1027024?v=4" width="100px;"/><br /><sub><b>Alasdair McLeay</b></sub>](https://github.com/penx)<br />[💡](#example-penx "Examples") |

<!-- ALL-CONTRIBUTORS-LIST:END -->

Expand Down
3 changes: 3 additions & 0 deletions examples/with-jest/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env", "react"]
}
6 changes: 6 additions & 0 deletions examples/with-jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ npm run test

Relative to [Jest documentation][jest-snapshot-documentation], you don't need to create snapshot manually.

### Outputting CSS to snapshots

If you are using Jest and Glamorous, you should also consider using [jest-glamor-react] so that your CSS gets outputted to snapshots and not just a hashed class.


#### Create react app

Using [Create react app][cra-repository], you won't be able to set `setupTestFrameworkScriptFile` configuration for Jest.
Expand All @@ -24,3 +29,4 @@ See [how to][cra-test-environment] use `testSetup.js` file in the CRA test envir
[cra-repository]: https://github.com/facebookincubator/create-react-app
[cra-test-environment]: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#initializing-test-environment
[jest-snapshot-documentation]: https://facebook.github.io/jest/docs/en/snapshot-testing.html
[jest-glamor-react]: https://github.com/kentcdodds/jest-glamor-react
24 changes: 17 additions & 7 deletions examples/with-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@
"scripts": {
"test": "jest --coverage"
},
"keywords": ["glamorous", "jest", "react"],
"keywords": [
"glamorous",
"jest",
"react"
],
"author": "pksjce",
"license": "ISC",
"dependencies": {
"enzyme": "^2.8.0",
"enzyme": "^2.9.1",
"glamorous": "^1.0.1",
"jest-glamor-react": "^1.2.0",
"react": "^15.4.2"
"jest-glamor-react": "^1.4.0",
"react": "^15.6.2"
},
"devDependencies": {
"enzyme-to-json": "^1.5.0",
"jest": "^19.0.2"
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"enzyme-to-json": "^1.6.0",
"jest": "^19.0.2",
"react-dom": "^15.6.2",
"react-test-renderer": "^15.6.2"
},
"jest": {
"testEnvironment": "jsdom",
"snapshotSerializers": ["enzyme-to-json/serializer"],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"setupTestFrameworkScriptFile": "./testSetup.js"
}
}
6 changes: 6 additions & 0 deletions src/__tests__/create-glamorous.with-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ test('resulting component can have its styles extended further', () => {
render(<View className={glamor.css({color: 'green'})} />),
).toMatchSnapshot('overriding styles via className')
})

test('resulting component gets sent valid props', () => {
const A = glamorous.div({}).withComponent('a')
const rendered = render(<A href="https://glamorous.rocks" />)
expect(rendered.prop('href')).toBe('https://glamorous.rocks')
})
8 changes: 8 additions & 0 deletions src/__tests__/index.with-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ test('allows you to provide any number of arguments for props', () => {
expectContext,
)
})

test('custom component with props to filter custom props', () => {
const MyComp = glamorous(props => <div {...props} />, {rootEl: 'div'})({})
const MyCompWithProps = MyComp.withProps({propA: true})
const rendered = render(<MyCompWithProps propB={true} />).find('div')
expect(rendered.prop('propA')).toBeUndefined()
expect(rendered.prop('propB')).toBeUndefined()
})
7 changes: 6 additions & 1 deletion src/create-glamorous.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function createGlamorous(splitProps) {
{
...componentProperties,
comp: newComp,
rootEl: getRootEl(newComp),
},
{
// allows the forwardProps and filterProps to be overridden
Expand Down Expand Up @@ -196,7 +197,7 @@ function createGlamorous(splitProps) {
// the base component, even when people wrap a glamorous
// component in glamorous
comp: componentsComp,
rootEl: rootEl || componentsComp,
rootEl: rootEl || getRootEl(comp),
// join forwardProps and filterProps
// (for anyone doing: glamorous(glamorous.a({}), {}))
forwardProps: when(comp.forwardProps, forwardProps),
Expand Down Expand Up @@ -250,6 +251,10 @@ function when(comp, prop) {
return comp ? comp.concat(prop) : prop
}

function getRootEl(comp) {
return comp.rootEl ? comp.rootEl : comp.comp || comp
}

function getDisplayName(comp) {
return typeof comp === 'string'
? comp
Expand Down

0 comments on commit 5942dad

Please sign in to comment.