Skip to content

Commit

Permalink
add tests for zero arity
Browse files Browse the repository at this point in the history
  • Loading branch information
planetcohen committed Nov 13, 2015
1 parent 6c504b9 commit e964931
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,53 @@ describe('React', () => {
expect(invocationCount).toEqual(2)
})

it('should invoke mapState every time props are changed if it has zero arguments', () => {
const store = createStore(stringBuilder)

let invocationCount = 0

@connect(() => {
invocationCount++
return {}
})

class WithoutProps extends Component {
render() {
return <Passthrough {...this.props}/>
}
}

class OuterComponent extends Component {
constructor() {
super()
this.state = { foo: 'FOO' }
}

setFoo(foo) {
this.setState({ foo })
}

render() {
return (
<div>
<WithoutProps {...this.state} />
</div>
)
}
}

let outerComponent
TestUtils.renderIntoDocument(
<ProviderMock store={store}>
<OuterComponent ref={c => outerComponent = c} />
</ProviderMock>
)
outerComponent.setFoo('BAR')
outerComponent.setFoo('DID')

expect(invocationCount).toEqual(4)
})

it('should invoke mapState every time props are changed if it has a second argument', () => {
const store = createStore(stringBuilder)

Expand Down Expand Up @@ -570,6 +617,54 @@ describe('React', () => {
expect(invocationCount).toEqual(1)
})

it('should invoke mapDispatch every time props are changed if it has zero arguments', () => {
const store = createStore(stringBuilder)

let invocationCount = 0

@connect(null, () => {
invocationCount++
return {}
})

class WithoutProps extends Component {
render() {
return <Passthrough {...this.props}/>
}
}

class OuterComponent extends Component {
constructor() {
super()
this.state = { foo: 'FOO' }
}

setFoo(foo) {
this.setState({ foo })
}

render() {
return (
<div>
<WithoutProps {...this.state} />
</div>
)
}
}

let outerComponent
TestUtils.renderIntoDocument(
<ProviderMock store={store}>
<OuterComponent ref={c => outerComponent = c} />
</ProviderMock>
)

outerComponent.setFoo('BAR')
outerComponent.setFoo('DID')

expect(invocationCount).toEqual(3)
})

it('should invoke mapDispatch every time props are changed if it has a second argument', () => {
const store = createStore(stringBuilder)

Expand Down

0 comments on commit e964931

Please sign in to comment.