forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mui#4548 from oliviertassinari/fix-render-to-layer…
…-context [RenderToLayer] Fix an internal issue with React
- Loading branch information
Showing
2 changed files
with
78 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-env mocha */ | ||
import {assert} from 'chai'; | ||
import React, {Component, PropTypes} from 'react'; | ||
import {mount} from 'enzyme'; | ||
import RenderToLayer from 'src/internal/RenderToLayer'; | ||
|
||
describe('<RenderToLayer />', () => { | ||
it('should pass updated muiTheme context if muiTheme context changes', () => { | ||
class Child extends Component { | ||
static contextTypes = { | ||
muiTheme: PropTypes.object.isRequired, | ||
}; | ||
|
||
render() { | ||
return <div>{this.context.muiTheme.foo}</div>; | ||
} | ||
} | ||
|
||
class Parent extends Component { | ||
static childContextTypes = { | ||
muiTheme: PropTypes.object.isRequired, | ||
}; | ||
|
||
state = { | ||
muiTheme: { | ||
zIndex: { | ||
layer: 1, | ||
}, | ||
foo: 'initial', | ||
}, | ||
}; | ||
|
||
getChildContext() { | ||
return { | ||
muiTheme: this.state.muiTheme, | ||
}; | ||
} | ||
|
||
renderLayer = () => { | ||
return <Child />; | ||
}; | ||
|
||
render() { | ||
return <RenderToLayer render={this.renderLayer} open={true} />; | ||
} | ||
} | ||
|
||
const instance = mount(<Parent />); | ||
const portal = document.body.lastChild; | ||
|
||
assert.strictEqual(portal.firstChild.innerHTML, 'initial'); | ||
instance.setState({ | ||
muiTheme: { | ||
zIndex: { | ||
layer: 1, | ||
}, | ||
foo: 'changed', | ||
}, | ||
}); | ||
assert.strictEqual(portal.firstChild.innerHTML, 'changed'); | ||
}); | ||
}); |