Skip to content

Commit

Permalink
change connect to take from context
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Mar 12, 2017
1 parent 42b8983 commit 4e231f0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/connect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {connect} from 'react-redux';
import {connectIntl} from 'redux-intl-connect';
import {connect as reduxConnect} from 'react-redux';
import injectIntl from './injectIntl';

export default connectIntl(connect);
function connect(...args) {
return (Component) => reduxConnect(...args)(injectIntl(Component));
}

export default connect;
34 changes: 34 additions & 0 deletions tests/connect.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import {expect} from 'chai';
import {shallow} from 'enzyme';
import {createStore, combineReducers} from 'redux';
import intlReducer from 'redux-intl-connect/lib/intlReducer';
import ValidateProp from './mocks/ValidateProp';
import Provider from '../src/Provider';
import connect from '../src/connect';

describe('connect', function () {
it('should provide intl context', function () {
const store = getStore();
const mapStateToProps = () => ({
others: ' too'
});
const Component = connect(mapStateToProps)(ValidateProp);

const App = () => (
<Provider store={store}>
<Component />
</Provider>
)
const app = shallow(<App />)
expect(app.html()).to.be.equal('<span>yes too</span>')
});

function getStore() {
const reducer = combineReducers({
intl: intlReducer,
})

return createStore(reducer);
}
});
8 changes: 7 additions & 1 deletion tests/mocks/ValidateProp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import isValidIntlObject from './isValidIntlObject';

const propTypes = {
intl: PropTypes.object,
others: PropTypes.string
}

const defaultProps = {
others: ''
}

function ValidateProp(props) {
const value = isValidIntlObject(props.intl) ? 'yes' : 'no';
return <span>{value}</span>
return <span>{value}{props.others}</span>
}

ValidateProp.propTypes = propTypes;
ValidateProp.defaultProps = defaultProps;
export default ValidateProp;

0 comments on commit 4e231f0

Please sign in to comment.