Skip to content

Commit

Permalink
test: Should child component constructor access context
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Sep 10, 2017
1 parent 55492e3 commit 19d16ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nervjs",
"version": "0.1.2",
"version": "0.1.3",
"description": "A react-like framework based on virtual-dom",
"main": "index.js",
"module": "dist/nerv.esm.js",
Expand Down
28 changes: 28 additions & 0 deletions test/modules/context.spec.js
Expand Up @@ -167,4 +167,32 @@ describe('context', () => {
render(<Outer />, scratch)
expect(scratch.innerHTML).to.equal('<div><strong>12</strong></div>')
})

it('Should child component constructor access context', () => {
const randomNumber = Math.random()
const CONTEXT = { info: randomNumber }
class Outer extends Component {
getChildContext () {
return CONTEXT
}
render () {
return <div><Inner /></div>
}
}

class Inner extends Component {
constructor (props, context) {
super(props, context)
expect(context.info).to.be.equal(CONTEXT.info)
this.state = {
s: null
}
}
render () {
return null
}
}

render(<Outer />, scratch)
})
})

0 comments on commit 19d16ef

Please sign in to comment.