Skip to content

Commit

Permalink
fix(test): add test for commit 386f07a and 682fe15.
Browse files Browse the repository at this point in the history
  • Loading branch information
littly committed Mar 15, 2018
1 parent 6f9caf6 commit f307fec
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/nerv/__tests__/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,48 @@ describe('Component', function () {
expect(clone.prototype).toEqual(instance.prototype)
})

it('should clone children as well', () => {
let inst
class Child extends Component {
render () {
return (
<div>
{this.props.children}
{this.props.children}
</div>
)
}
}

class Daddy extends Component {
constructor () {
super(...arguments)
this.state = {
xxx: 'xxx'
}
inst = this
}
render () {
const xxx = this.state.xxx
return (
<Child>
{xxx ? <div>{xxx}</div> : ''}
</Child>
)
}
}

expect(() => {
render(
<Daddy />,
scratch
)
inst.setState({ xxx: false })
inst.forceUpdate()
}).not.toThrow()
expect(scratch.innerHTML).toEqual('<div></div>')
})

it('should remove children when root changes to text node', () => {
let comp
class Comp extends Component {
Expand Down Expand Up @@ -428,6 +470,16 @@ describe('Component', function () {
expect(dom.firstChild.textContent).toEqual('null')
expect(dom.lastChild.textContent).toEqual('aaa')
})

it('(StatelessComponent) should support function returning null', () => {
const FunctionReturningNull = () => null
expect(() => {
render(
<FunctionReturningNull />,
scratch
)
}).not.toThrow()
})
})

describe('setState', () => {
Expand Down

0 comments on commit f307fec

Please sign in to comment.