File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,12 @@ export default function createConnect(React) {
88
88
this . version = version ;
89
89
this . store = props . store || context . store ;
90
90
91
- invariant ( this . store , '`store` must be passed in via the context or props' ) ;
91
+ invariant ( this . store ,
92
+ `Could not find "store" in either the context or ` +
93
+ `props of "${ this . constructor . displayName } ". ` +
94
+ `Either wrap the root component in a <Provider>, ` +
95
+ `or explicitly pass "store" as a prop to "${ this . constructor . displayName } ".`
96
+ )
92
97
93
98
this . stateProps = computeStateProps ( this . store ) ;
94
99
this . dispatchProps = computeDispatchProps ( this . store ) ;
Original file line number Diff line number Diff line change @@ -739,6 +739,26 @@ describe('React', () => {
739
739
expect ( actualState ) . toEqual ( expectedState ) ;
740
740
} ) ;
741
741
742
+ it ( 'should throw an error if the store is not in the props or context' , ( ) => {
743
+ class Container extends Component {
744
+ render ( ) {
745
+ return < div /> ;
746
+ }
747
+ }
748
+
749
+ const decorator = connect ( state => { } ) ;
750
+ const Decorated = decorator ( Container ) ;
751
+ const expectedError =
752
+ `Invariant Violation: Could not find "store" in either the context ` +
753
+ `or props of "Connect(Container)". Either wrap the root component in a ` +
754
+ `<Provider>, or explicitly pass "store" as a prop to "Connect(Container)".` ;
755
+
756
+ expect ( ( ) => TestUtils . renderIntoDocument ( < Decorated /> ) ) . toThrow ( e => {
757
+ expect ( e . message ) . toEqual ( expectedError )
758
+ return true
759
+ } )
760
+ } )
761
+
742
762
it ( 'should return the instance of the wrapped component for use in calling child methods' , ( ) => {
743
763
const store = createStore ( ( ) => ( { } ) ) ;
744
764
You can’t perform that action at this time.
0 commit comments