Skip to content

Commit

Permalink
fix(defaultProps): Get defaultProps from the wrapped component; Add t…
Browse files Browse the repository at this point in the history
…ests

Previous commit added support for defaultProps coming into stateless components.  This adds the same
for class-based components.  Adds test for each case.
  • Loading branch information
jaketrent committed Feb 8, 2016
1 parent 14baa3e commit 2cff7b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/__specs__/styleable.spec.js
Expand Up @@ -11,9 +11,12 @@ const css = {
function mkFixture(css) {
@styleable(css)
class Subject extends React.Component {
static defaultProps = {
aDefault: 'still here'
};
render() {
return (
<div className={this.props.css.content} ref="content">Content</div>
<div className={this.props.css.content} ref="content">Content {this.props.aDefault}</div>
)
}
}
Expand All @@ -23,7 +26,10 @@ function mkFixture(css) {

function mkFunctionFixture(css) {
function subject(props) {
return <div className={props.css.content}>Content</div>
return <div className={props.css.content}>Content {props.aDefault}</div>
}
subject.defaultProps = {
aDefault: 'still here'
}

return styleable(css)(subject)
Expand Down Expand Up @@ -96,6 +102,12 @@ describe('styleable', () => {
component.props.css.content.should.eql(newHash )
})

it('lets defaultProps pass through', () => {
const Subject = mkFixture()
const component = TestUtils.renderIntoDocument(<Subject />)
component.props.aDefault.should.eql('still here')
})

describe('with stateless functions', () => {

it('makes the css prop available', () => {
Expand All @@ -114,6 +126,12 @@ describe('styleable', () => {
ReactDOM.findDOMNode(component).children[0].className.should.eql(newHash)
})

it('lets defaultProps pass through', () => {
const Subject = mkFunctionFixture()
const component = TestUtils.renderIntoDocument(<div><Subject /></div>)
ReactDOM.findDOMNode(component).children[0].textContent.should.eql('Content still here')
})

})

})
})
1 change: 1 addition & 0 deletions src/styleable.js
Expand Up @@ -53,6 +53,7 @@ export default function styleable(stylesheet) {
return class Styleable extends React.Component {
static displayName = `Styleable(${getDisplayName(DecoratedComponent)})`;
static defaultProps = {
...DecoratedComponent.defaultProps,
css: {}
};
static propTypes = {
Expand Down

0 comments on commit 2cff7b7

Please sign in to comment.