Skip to content

Commit e964931

Browse files
committed
add tests for zero arity
1 parent 6c504b9 commit e964931

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

test/components/connect.spec.js

+95
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,53 @@ describe('React', () => {
469469
expect(invocationCount).toEqual(2)
470470
})
471471

472+
it('should invoke mapState every time props are changed if it has zero arguments', () => {
473+
const store = createStore(stringBuilder)
474+
475+
let invocationCount = 0
476+
477+
@connect(() => {
478+
invocationCount++
479+
return {}
480+
})
481+
482+
class WithoutProps extends Component {
483+
render() {
484+
return <Passthrough {...this.props}/>
485+
}
486+
}
487+
488+
class OuterComponent extends Component {
489+
constructor() {
490+
super()
491+
this.state = { foo: 'FOO' }
492+
}
493+
494+
setFoo(foo) {
495+
this.setState({ foo })
496+
}
497+
498+
render() {
499+
return (
500+
<div>
501+
<WithoutProps {...this.state} />
502+
</div>
503+
)
504+
}
505+
}
506+
507+
let outerComponent
508+
TestUtils.renderIntoDocument(
509+
<ProviderMock store={store}>
510+
<OuterComponent ref={c => outerComponent = c} />
511+
</ProviderMock>
512+
)
513+
outerComponent.setFoo('BAR')
514+
outerComponent.setFoo('DID')
515+
516+
expect(invocationCount).toEqual(4)
517+
})
518+
472519
it('should invoke mapState every time props are changed if it has a second argument', () => {
473520
const store = createStore(stringBuilder)
474521

@@ -570,6 +617,54 @@ describe('React', () => {
570617
expect(invocationCount).toEqual(1)
571618
})
572619

620+
it('should invoke mapDispatch every time props are changed if it has zero arguments', () => {
621+
const store = createStore(stringBuilder)
622+
623+
let invocationCount = 0
624+
625+
@connect(null, () => {
626+
invocationCount++
627+
return {}
628+
})
629+
630+
class WithoutProps extends Component {
631+
render() {
632+
return <Passthrough {...this.props}/>
633+
}
634+
}
635+
636+
class OuterComponent extends Component {
637+
constructor() {
638+
super()
639+
this.state = { foo: 'FOO' }
640+
}
641+
642+
setFoo(foo) {
643+
this.setState({ foo })
644+
}
645+
646+
render() {
647+
return (
648+
<div>
649+
<WithoutProps {...this.state} />
650+
</div>
651+
)
652+
}
653+
}
654+
655+
let outerComponent
656+
TestUtils.renderIntoDocument(
657+
<ProviderMock store={store}>
658+
<OuterComponent ref={c => outerComponent = c} />
659+
</ProviderMock>
660+
)
661+
662+
outerComponent.setFoo('BAR')
663+
outerComponent.setFoo('DID')
664+
665+
expect(invocationCount).toEqual(3)
666+
})
667+
573668
it('should invoke mapDispatch every time props are changed if it has a second argument', () => {
574669
const store = createStore(stringBuilder)
575670

0 commit comments

Comments
 (0)